在ASP.NET Core中,处理URL问题的常见解决方法包括以下几种:
public IActionResult Index()
{
string url = Url.Action("ActionName", "ControllerName");
// ...
}
public IActionResult Index()
{
var routeValues = new RouteValueDictionary
{
{ "id", 1 },
{ "name", "John" }
};
string url = Url.Action("ActionName", "ControllerName", routeValues);
// ...
}
public IActionResult Index()
{
string currentUrl = HttpContext.Request.GetDisplayUrl();
// ...
}
public IActionResult Index()
{
return RedirectToAction("ActionName", "ControllerName");
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// ...
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "customRoute",
pattern: "myroute/{id}/{name}",
defaults: new { controller = "Home", action = "Index" });
});
}
以上是一些常见的解决方法,根据具体的URL问题,可能还会有其他的解决方案。