As mentioned in a previous posting, Fiddler can be a great tool when debugging HTTP-based communication, particularly for webservices, WCF and similar (but really, any kind of HTTP traffic can be debugged with the tool). There is just one slight problem with it: by default, it is not usable for debugging localhost-based servers. In other words: if your server URL looks something like http://localhost:12345/MyService.asmx, you will not be able to debug it with Fiddler. That is, unless you apply “The Dot Trick”, which will be described in this blog posting.
First, let’s discuss the apparent problem and its cause, then we’ll move on to how we can workaround this. Let’s create a scenario: You are having problems with a web request in an application; the web request causes an exception for some reason. More specifically, the request is from a web application (ASP.NET .aspx file) to a web service (.asmx file). Also, you cannot/don’t want to debug this using Visual Studio’s built-in debugger, for one reason or another. This is the error message you’re getting, as presented on the ASP.NET web page:
Now, let’s start Fiddler. This is the output we get:
Switch back to IE, and press F5 to refresh the page (and hopefully reproduce the problem). After doing this, the error appears again in the web page, but… if you now look in the Fiddler window, it looks exactly the same as before you hit F5. How could this be, what on earth is happening?!?
The answer is this, taken from the Fiddler web page: “Internet Explorer and the .NET Framework are hardcoded not to send requests for Localhost through any proxies, and as a proxy, Fiddler will not receive such traffic” [1] This makes sense if you think about it: a proxy running somewhere in your local network can not fetch data from your local machine, when accessing a localhost-based URL. It could do a best-effort and try to rewrite the url to http://yourmachine:12345 (where yourmachine is the name of your machine), using the IP address provided in the proxy request, but… there’s no guarantee that http://yourmachine:12345 would be the same as your local http://localhost:12345 URL. In fact, when using the Visual Studio built-in web server (a.k.a. Cassini), this would not work at all: Cassini is designed to only listen on localhost traffic!
Therefore, it is understandable that someone at Microsoft at some point took the decision that WinINET and/or IE/Microsoft.NET should disregard proxy configurations for localhost-based URL:s.
So, having stated what the problem is and some theory behind it, let’s move on to the whole point of this blog posting: There is a nifty little workaround to this problem, making it possible to debug traffic to localhost in Fiddler! But only if you have a way to modify the URL, so in some cases it would still be hard/impossible to use this. In our specific use case (an ASP.NET page calling a webservice) though, we can benefit greatly from knowing this. The workaround is what we can call “the Dot Trick”.
What you simply do is this: change the URL from something like http://localhost:12345/MyService.asmx to be http://localhost.:12345/MyService.asmx. Did you notice the dot? Right after the “localhost” and before the colon a dot (period character) has been inserted. This is what the browser window with the ASP.NET page looks like now (very similar to before, only difference being that the dot has been inserted in the URL):
But now look at our Fiddler buddy! This is what the Fiddler window contains:
Much better, isn’t it? We can now investigate “the red line” and possibly see what was causing this problem. However, that is out of the scope for this blog posting. :-)
Alright, that’s it for this time. In this blog posting, we’ve learned one of the caveats of Windows HTTP traffic, and how to work around it. I hope the information was useful to some of you; it has sure helped me.
PS: Rumor has it that “the dot trick” sometimes doesn’t work, e.g. with Windows 7. In that case, you can try http://ipv4.fiddler:12345/MyService.asmx instead. This will be intercepted by Fiddler and converted to localhost:12345, intercepting the traffic as needed.












