Making the URL of a request lowercase in global.asax or an HTTP Module in ASP.NET 2.0

Hello,
I have an ASP.NET 2.0 application that runs in IIS 6.0 and I wanted to know if there is a way to convert any incoming page request to lowercase (e.g. from http://www.site.com/Folder/SUBFOLDER/PageInPascal.aspx tp http://www.site.com/folder/subfolder/pageinpascal.aspx).  I can't use the routing features in IIS 7.0 and rewriting features in ASP.NET 3.5.

Is there a way to take the current request and make it lower case in either the global.asax file or an HTTP Module and how would I do that?
endrecAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

masterpassCommented:
Try this code, its very simple

It is in the Application_BeginRequest of global.asax
protected void Application_BeginRequest(object sender, EventArgs e)
{
string requestedUrl = Request.Url.AbsoluteUri.ToLower();
//do the rest here 
}

Open in new window

0
Carl TawnSystems and Integration DeveloperCommented:
Converting to lowercase is simple enough. What is the context? Where do you want it to appear in lower case, or why specifically do you need it to be lower case?
0
endrecAuthor Commented:
The files on the site are named using different casing and frankly some users find it strange looking.  It's purely for that reason.  The context would be the current request.

So if the user, or a link points to, ~/FoLder/PAGE.aspx when the user clicks that link or is redirected that page via an Respons.Redirect how could I dynamically convert the entire URL that appears in their browser's address bar to lowercase (including all querystrings in the URL).
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Carl TawnSystems and Integration DeveloperCommented:
You might have to resort to using javascript to accomplish what you want, otherwise you're going to have to do a Redirect on each request, which is going to double the hits on your server.
0
endrecAuthor Commented:
The redirect would actually be fine in this case.
0
masterpassCommented:
In that case tolower() is the simplest one that you can do ..  
0
endrecAuthor Commented:
Hello Masterpass,
So would using the code you outlines for Application_BeginRequest convert the user's current request (including all the querystrings) URL to lower case or is there something extra that needs to be added for the querystrings to also be included?

Thank you for your help
0
Carl TawnSystems and Integration DeveloperCommented:
Masterpass's suggestion of simply putting ToLower() in the BeginRequest won't work because doing a Response.Redirect from that method call will simply create an infinite loop.
0
masterpassCommented:
You can use the ToLower() to redirect. I have attached the code how to go about it and it will NOT create a infinite loop. Also this is a code snippet we use in our projects
// Check url 
if (Regex.IsMatch(HttpContext.Current.Request.Url.ToString(), @"[A-Z]"))
{

    // Lowercase url  
    String lower = HttpContext.Current.Request.Url.ToString().ToLower();

    // Redefine response  
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.Status = "301 Moved Permanently";
    HttpContext.Current.Response.AddHeader("Location", lower);
    HttpContext.Current.Response.End();

}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
endrecAuthor Commented:
Hi Masterpass,
I turned this into an HttpModule, but I wondered if you ever run into exceptions on Response.End with the thread being aborted.  You have masterfully answered my query, however I just wanted to inquire if you see any problems if I use Response.End.

http://www.west-wind.com/WebLog/posts/368975.aspx
http://www.hanselman.com/blog/AnIPAddressBlockingHttpModuleForASPNETIn9Minutes.aspx (see comments)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.