How to add page title in url in asp.net mvc? (url generation)
asp.net-mvc, routes, seo, url
Solution
You have to use something as follows.
Routes.MapRoute(
"Post",
"posts/{id}/{*title}",
new { controller = "Posts", action = "view" }
);
And a simple extension method:
public static class UrlExtensions
{
public static string ResolveSubjectForUrl(this HtmlHelper source, string subject)
{
return Regex.Replace(Regex.Replace(subject, "[^\\w]", "-"), "[-]{2,}", "-");
}
}
Problem
How to dynamically create urls/links like: www.restaurant.com/restaurant/restaurant-name-without-some-characters-like-space-coma-etc/132 what are the keywords i can use to google some articles on this topic? (how to genererate and handle this kind of urls inside asp.net mvc) There are some questions: How to generate links? (store slugs in db?) Redirect or not if slug isn't canonical? edit: apparently they are called slugs