find a location for property in a new city

Friday, 18 March 2011

Firefox loses Request headers after redirect

Firefox does not remember some request headers after a redirect. This can cause problems with AJAX requests that use the X-Requested-With: XmlHttpRequest header.

I noticed a little problem with Firefox. In my scenario I have added the SEO optimising IIS Url Rewriting module pattern that redirects URL with upper case in to a lower case version.

For all browsers the AJAX request comes in with the X-Requested-With: XmlHttpRequest request header, a 301 status code is returned with the lower cased location, that new location then is requested with the X-Requested-With: XmlHttpRequest header in tact.

Firefox, however, does not honour this header in its redirect. This causes problems with my ASP.NET MVC code that checks for the request being via AJAX using IsAjaxRequest(). This method checks if X-Requested-With: XmlHttpRequest is in the headers (or in other exciting places).

Work around

I was going to try and do something clever like detect the browser and this header and then not redirect under some circumstances because (brace yourself SEO consultants) functionality is more important than SEO. I decided to instead make sure that one troublesome link was lowercase and so avoided the redirect.

Just hope this answers your questions if you come across this oddity in Firefox.

Follow britishdev on Twitter

6 comments:

  1. what if I still want firefox to redirect? without loosing the header (its a custom header I added), the header can be recognized by IE but not firefox.

    ReplyDelete
  2. I don't believe you can. I have come into this issue again with the Referer [sic] header disappearing (in Chrome). The best cause of action is to not have a redirect (unfortunately).

    I can't think of another way of telling the user's browser to redirect *and* retain a header. Unless you store the info in a cookie if that is appropriate.

    ReplyDelete

  3. Thanks for posting this useful content, Good to know about new things here, Let me share this, . Hadoop training in pune

    ReplyDelete
  4. Interesting post! This is really helpful for me. I like it! Thanks for sharing!

    Webseiten Gestaltung L├╝denscheid

    ReplyDelete