About this Article
We aware of that our Asp .Net MVC application generate mixed-case URLs like https://dotnet-helpers.com/Home/About or https://dotnet-helpers.com/home/about. So if we type URLs then itย wont consider the upper case or lower case.ย In ASP.NET MVC, route generates outgoing URLs based on the casing of our controller and action names.ย By default, ASP.NET MVC controllers are classes and actions are methods,so these outgoing URLs are likely be camel-case.
Having Two URLs make problem in Search Rankings:
In ASP.NET MVC, the URLs generated by the routing mechanism are based on the controller and action names. Technically be considered , this will lead to duplicate pages with the same content.ย Most SEOs will recommend sticking to have only one version.
Solution :
LowercaseUrls property on the RouteCollection class has introduced in ASP .NET 4.5.ย Using this property we can lowercase all of our URLs.
Eg : routes.LowercaseUrls = true;
Example :
RouteConfig.cs
Include below pieace of code in the RouteConfig.cs file to convert all the URLs in to lowercase.
1 2 3 4 5 |
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); |
1 2 3 4 5 6 7 |
routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }); } } |
Controller:
A simple controller which has two action method namely LowerCaseUrls and LoadUserDetails.
1 2 3 4 5 6 7 8 9 10 11 12 |
public class dotnethelpersController : Controller { public ActionResult LowerCaseUrls() { return View(); } public ActionResult LoadUserDetails() { return View(); } } |
LowerCaseUrls.cshtml :
1 2 3 4 5 6 7 8 9 10 11 12 |
<!DOCTYPE html> <html> <head> <title>LowerCaseUrls</title> </head> <body> <div> @Html.ActionLink("Home", "LoadUserDetails", "Dotnethelpers") </div> </body> </html> |
Output:
After clicking the HOME Link it redirecting to the dotnethelpers/loaduserdetails instead of Dotnethelpers/LoadUserDetails
Keep Happy Coding !!!
Leave A Comment