-1

I am working with asp.net mvc 4 and have some issues around routing.

  • how do I ensure that all routes generated on the site via url's etc to be lower case? I have set RouteTable.Routes.LowercaseUrls = true; but the urls are still being generated in uppercase etc. Am I missing something?

  • I want to tweak my routes so that I no longer have /Home/About/Index to /Home/About - so that the Index is dropped when the route is generated - how can this be done.

Finally, this is my route configuration.

RouteTable.Routes.MapRoute("MyRoute", "home/{action}", 
    new { controller = "About" });
gunr2171
  • 16,104
  • 25
  • 61
  • 88
amateur
  • 43,371
  • 65
  • 192
  • 320

1 Answers1

1

I use something like this, when I don't use UrlRewrite in IIS to handle lowercase routes

Install this NuGet package: http://lowercaseroutesmvc.codeplex.com/

using LowercaseRoutesMVC
 ...

public static void RegisterRoutes(RouteCollection routes)
{
   routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

   routes.MapRouteLowercase( // changed from routes.MapRoute
       "Default",
       "{controller}/{action}/{id}",
       new { controller = "Home", action = "Index", id = UrlParameter.Optional }
   );
}

Check the accepted answer on this SO post describing UrlRewrite Lowercase Urls IIS URL rewrite module url's to lowercase

Community
  • 1
  • 1
Anthony Shaw
  • 8,146
  • 4
  • 44
  • 62