例如,我有一个About Us
页面:
htttp://localhost/About/Index
如何为此页面提供用户友好的网址?
http://localhost/about-us.html
我目前的解决方法:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "AboutPage",
template: "about-us.html",
defaults: new {controller = "About", action = "Index"});
});
}
这是错误的做法。如何正确映射路由,以便在cshtml页面中使用@Url.Action("Index", "About")
时,它会为我生成链接/about-us.html
?
答案 0 :(得分:1)
您可以使用以下自定义网址:
[Route("about-us.html")]
public IHttpActionResult Index()
{
return Ok("About us");
}