2

We are using a CMS application developed in asp.net 4 with URL rewrite extension. Our application is hosting thousands of CMS pages and in solution Response.Redirect has been numerously used with URLs containing UPPER CASE letters. On using URL rewrite rule to convert requested URLs to lower case causing 301 status code for any page with Upper Case letter in its URL, which is not good for SEO perspective.

So I am looking forward a way to intercept those all Response.Redirect calls from a single location i.e. from global file, and convert them into lower case, rather then go in code files and convert all URLs pass to response.redirect method to lower case.

  • maybe you can handle application_beginrequest or application_prerequesthandlerexecute in global.asax file? – Monah Nov 06 '14 at 20:21
  • yap thats wat I m looking forward to implement IHttpModule with logic to intercept those redirect calls. – Mohtisham Zubair Nov 06 '14 at 20:44
  • check this article that might help you hopefully http://msdn.microsoft.com/en-us/magazine/cc301704.aspx – Monah Nov 06 '14 at 20:52
  • @HadiHassan I m interested in background of Response.Redirect as mentioned [link] (http://msdn.microsoft.com/en-us/library/a8wa7sdt%28v=vs.100%29.aspx) so that I can intercept and changes URLs pass to this method and convert them into lower case to stop the status code consequences. – Mohtisham Zubair Nov 06 '14 at 21:02

1 Answers1

1

After getting into the MSDN and digging out Response.Redirect is setting location Header which does support get/set.

void Application_EndRequest(object sender, EventArgs e)
{
    HttpApplication application = sender as HttpApplication;
    HttpContext context = application.Context;

    if (context.Response.IsRequestBeingRedirected)
    {
        string redirectedLocation = context.Response.Headers["Location"];
        context.Response.Headers["Location"] = redirectedLocation.ToLowerInvariant();
    }

}