Normal routing in asp.net mvc is not much SEO friendly. Commonly we are using {controller}/{action}/id route by default.
Default routing:
routes.MapRoute(
"Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults );normally we are using an integer number in the place of id (usually database table keys). Urls like this is not SEO friendly ( eg: www.yourdomain.com/Location/details/2). If we can build a url with string which is the name of the particular item( eg: location,book,movie etc). it will become more SEO friendly. Such as www.yourdomain.com/Location/details/Location name.
This is possible in asp.net mvc by adding one more route in Global.asax. Note that newly added url parameter must be optional because we dont need that parameter in normal cases. It's been purely using for SEO.
Here is the Global.asax code.
routes.MapRoute( "Default1", // Route name "{controller}/{action}/{id}/{id1}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional, id1 = UrlParameter.Optional } // Parameter defaults );
Add the above code also in Global.asax Default route.
The action will be like this
[OutputCache(CacheProfile = "Cache1Hour")] public ActionResult Details(decimal id, string id1) { CDataStructLocationDetails objeDetails = new CDataStructLocationDetails{Id = id,Typeid =3}; return ViewEx(EnActions.Details, objeDetails); }
Sample Urls:
www.yourdomain.com/Package/Details/5/Kerala-Honeymoon-Package.
Blank spaces in Urls replaced by %20 to avoid this we can send the name by replacing blank spces with '-'
here is the sample.
<%= Html.ActionLink("View Package Details", "Details",
new{id=item.Id,id1=item.PackageName.Trim().Replace(' ','-')})%>
2 comments:
Good post!!
A suggestion would be to move the logic of replacing spaces with hyphen into the action links logic, so that the view developer doesn't have to write extra logic.
The content of your blog is exactly what I needed, I like your blog, I sincerely hope that your blog a rapid increase in traffic density, which help promote your blog and we hope that your blog is being updated .
Joomla developer
Post a Comment