making URL lowercase. Any easy or builtin way?

I've just noticed that there is a new property in .NET Framework 4.5. Works great! RouteCollection.LowercaseUrls

Set LowercaseUrls to true

public static void RegisterRoutes(RouteCollection routes)
{
    routes.LowercaseUrls = true;
    ...
}

Create a link

@Html.ActionLink("Log in", "Login", "Account")

That will create awesome, lowercase url :)

<a href="/account/login">Log in</a>

There is a NuGet package for this : LowerCaseRoutesMVC (Project website)


If your reasons for enforcing lowercase is purely SEO, then the best solution that I have found is to use the IIS 7 URL Rewrite Module

Not only do you have the ability to force all url's to lowercase but you also have access to rules that allow you to remove/add trailing slashes, enforce canonical domains etc.

RuslanY's Blog has a good set to start from. For example, I use the following on all of my sites:

<!-- http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/ -->
<rule name="Convert to lower case" stopProcessing="true">
    <match url=".*[A-Z].*" ignoreCase="false" />
    <conditions>
        <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="GET" ignoreCase="false" />
    </conditions>
    <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>

You simply add the above lines to the section of your web.config.


Yes, I have had to implement something similar to the above. It appears to be the only smooth way to accomplish this.

I would like to add that in addition, we added 301 redirects so that any traffic coming from /Upper-Case-Url will be 301 redirected to /upper-case-url.