views:

67

answers:

2

I am working on a .NET MVC application and am trying to write a route in global.asax.cs. The goal is, I want any URL that contains an uppercase character to run through said route. The idea is, the router will lowercase the URL and redirect it. My approach is to use a regular expression to handle this. Here's what I have:

routes.MapRoute(
    "CanonicalizationRoute", 
    "{*url}", 
    new 
    { 
        controller = "CanonicalRouter", 
        action = "Reroute" 
    }, 
    new 
    { 
        url = @"[A-Z]+" 
    });

Doesn't seem to do the trick...any thoughts on how best to handle this?

A: 

By any chance are you running IIS 7? The URL Rewrite module provides a nice way of handling this outside of your application (configured in the web.config file). Here's a blog post about it, including your specific need.

Untested, but as for your code issue, maybe the regex needs to allow characters besides uppercase letters? ".*[A-Z]+.*"

Chris Shaffer
A: 

If you're just looking to support lower-case routes (basically making your routes case-insensitive), you might see this. We're currently using this and it works great.

From this SO post.

Andrew Flanagan