Is is possible to make SEO friendly Url's in ASP.NET Core like this one

有些话、适合烂在心里 提交于 2019-12-11 03:54:36

问题


I wanted to ask you guys if is it possible, to make some routing like this for my project /{action}/{title}?

I was wondering if that is possible, does this url has to be a primary key too? Since there is no ID passed to know which blog post is this.

Thank you.


回答1:


You can do this quite easily with attribute routing:

[Route("blogs")]
public class BlogController
{
    [AcceptVerbs("GET", "HEAD", Route = "{slug}")]
    public IActionResult View(string slug)
    {
    }
}

This maps all requests to /blogs/whatever to that action, and sets slug to the value after "/blogs/".



来源:https://stackoverflow.com/questions/47790317/is-is-possible-to-make-seo-friendly-urls-in-asp-net-core-like-this-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!