问题
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