Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to handle seo friendly routing in asp.net core like asp.net mvc ?

$
0
0

I have seo friendly routing in asp.net mvc which basically ads title along with id but upon called it passes id to action but show title + id in url.

Here is the code.

 routes.Add("ClinicDetails",newSeoFriendlyRoute("veterinary-clinics/{id}/details",newRouteValueDictionary(new{ controller ="clinics", action ="details"}),newMvcRouteHandler()));publicclassSeoFriendlyRoute:Route{publicSeoFriendlyRoute(string url,RouteValueDictionary defaults,IRouteHandler routeHandler):base(url, defaults, routeHandler){}publicSeoFriendlyRoute(string url,RouteValueDictionary defaults,IRouteHandler routeHandler,IEnumerable namespaces):base(url, defaults, routeHandler){DataTokens= defaults;
            defaults["Namespaces"]= namespaces;}publicoverrideRouteDataGetRouteData(HttpContextBase httpContext){var routeData =base.GetRouteData(httpContext);if(routeData ==null)returnnull;if(routeData.Values.ContainsKey("id"))
                routeData.Values["id"]=GetIdValue(routeData.Values["id"]);return routeData;}privateobjectGetIdValue(object id){if(id ==null)returnnull;var idValue = id.ToString();var regex =newRegex(@"^[\w|\W]+-(?<id>\d+).*$");var match = regex.Match(idValue);return match.Success? match.Groups["id"].Value: id;}}

How i can get this same functionality in asp.net core.

https://stackoverflow.com/questions/47219941/seo-friendly-routing-in-asp-net-core


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>