Lowercase Routes in ASP.NET MVC

I don’t know about you, but I believe all URLs should be lowercase. Seeing a URL with uppercase letters always seems wrong to me, and frankly, I think looks kind of ugly. This goes for intranet web apps as well.

Historically, in ASP.NET MVC apps, you have to take care of this yourself. For example, when using Url.Action() you can pass in lowercase controller and action names and you’ll get lowercase URLs. But this convention is easily missed, especially with multiple developers writing code, and then you end up with some URLs lowercased and some not. Ugh.

However, .NET 4.5 introduced the LowercaseUrls property on the RouteCollection class, which means you can lowercase all of your URLs with this one line of code:

There are a couple caveats:

  • It only works in .NET 4.5 or higher.
  • If the query string is part of the URL, that part of the URL will not be converted to lowercase (and understandably so).

I don’t know how I missed this before, but it’s now one of the first things I add when starting new ASP.NET MVC projects. And if anyone asks me, I’d vote for the LowercaseUrls property set to true by default :-)

Featured Image: Some rights reserved by arnoKath

One comment

  1. Jan says:

    From an SEO perspective, uppercase & lowercase mean two different things & will get indexed differently. Whatever your scheme is, make it consistent. (imo lowercase as well)

Leave a Reply

Your email address will not be published. Required fields are marked *