I\'m trying to find a good general purpose way to canonicalize urls in an ASP.NET MVC 2 application. Here\'s what I\'ve come up with so far:
// Using an authoriz
I have felt the same "itch" regarding the relaxed nature of the default ASP.NET MVC routing, ignoring letter casing, trailing slashes, etc. Like you, I wanted a general solution to the problem, preferably as part of the routing logic in my applications.
After searching the web high and low, finding no useful libraries, I decided to roll one myself. The result is Canonicalize, an open-source class library that complements the ASP.NET routing engine.
You can install the library via NuGet: Install-Package Canonicalize
And in your route registration: routes.Canonicalize().Lowercase();
Besides lowercase, several other URL canonicalization strategies are included in the package. Force www
domain prefix on or off, force a specific host name, a trailing slash, etc. It is also very easy to add custom URL canonicalization strategies, and I am very open to accept patches adding more strategies to the "official" Canonicalize distribution.
I hope you or anyone else will find this helpful, even if the question is a year old :)