IamCalvinBrown.com a Blog Site

Code Examples, Consulting Advice and lots of other cool things

Make all urls lowercase in MVC


The line highlighted in yellow sets all urls to lower case. this is more visually appealing to the users and less confusing with longer urls.

public static void RegisterRoutes(RouteCollection routes)

        {

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


            routes.LowercaseUrls = true;


            routes.MapRoute(

                   "Default",

                   "{action}",

                   new { controller = "Home", action = "Index" }

               );


            routes.MapRoute(

                "Index", // Route name

                "{controller}/{action}/{id}", // URL with parameters

                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults

            );


        }

Loading