Infinite 302 Loop – How would you even know?

trav-053 It happens eventually to all web developers.  It’s happened to me twice in the last week.  You make one simple change to your web site and then you can no longer access it.  When you browse to it in IE you get some completely useless “We can’t access the page you are looking for” error.  In FireFox, it at least tells you that you have a “Redirect Loop” and in IE6, if you are fortunate enough to still be writing for that browser, you can see that it is blinking at you as it tries to retrieve the page(s) multiple times.  But how do you know what’s redirecting to what?

For that matter, other than running a browser that told you, how would you even know it was a 302 error?

I know I’ve mentioned this before but it’s definitely worth repeating.  Get yourself a copy of Fiddler.  Fiddler is a proxy that runs on local host.  By default when you run it, it automatically installs itself as a proxy in IE so you really don’t have to know much more than how to install software to get up and running with it.

When you access a web site with it, it will tell you everything that is going on.  What headers are being sent.  What headers are coming back from the server.  Files that are being requested.  Status codes that are coming back.

Any time I have a client-side problem with my web sites, or any time I have a problem with my web sites that I can’t explain from the server side, I reach for Fiddler.  More often than not, it tells me or at least guides me to what the real problem is.

For example, last week I was given the task of creating a 301 redirect from one domain to another.  I thought I had the code written correctly to do this, but when we went to access the domain it went into an infinite loop.  Obviously something was wrong, but what?

When I ran similar code on other domains it worked correctly.

When I ran Fiddler, I found that the page was redirecting to itself multiple times.  Odd.  What would make it do that?

So back to my code, where I quickly discovered that I had left out a character in my replace function so that domain A was never being rewritten to domain B so domain A was constantly redirecting to itself.

This morning’s error was a little more fun.  My designer was trying to install a module into DotNetNuke last night when the site suddenly “stopped working.”

Same deal.  Only this time it is because there is some module that is redirecting from the home page to another page and then that other page is redirecting back to the home page.

Again, I would have never been able to track this down if I hadn’t had Fiddler to help me.

I’ve also used this to verify that javascript tracking codes are working correctly.  If you need to see traffic that is going between the browser and the server, Fiddler is the tool you are looking for.

Related Post

  • Response.Redirect() and JavaScriptResponse.Redirect() and JavaScript Yesterday we covered issues surrounding using Response.Redirect in server side code. We noted that not handing it correctly could prevent code from running on the server that we want to run. T...
  • DotNetNuke Modules – Creating Base ModulesDotNetNuke Modules – Creating Base Modules Now that we have DotNetNuke installed into Visual Studio we can go ahead and create our first modules. Actually, creating the modules is pretty simple. But it is even easier to do it wrong, which...
  • Response.Redirect() executes too soon on the Server.Response.Redirect() executes too soon on the Server. I've seen this question a couple of times in various situations. The first involves Javascript and the second involves server side code. Both are caused by a misunderstanding of what this functi...
  • Test Your Web Site Using Multiple Web BrowsersTest Your Web Site Using Multiple Web Browsers So, I routinely need to test the web sites I create in both IE7 and IE6.  I wouldn't care so much about IE6 if it weren't for the fact that some people will never be able to upgrade to IE7 without ...
  • Automated Web Testing with the WebBrowserControlAutomated Web Testing with the WebBrowserControl Actually, I used this technique to automate submitting information to a set of web sites, but you could use this same technique to script any web site, including one you are currently developing...