39

I am using IIS7 Express while developing my web application. I need to use fiddler to investigate an issue and cannot figure out how to configure things so I can get the HTTP stream. It seems that IIS7 express will only listen on localhost which means I cannot access the stream.

Brettski
  • 19,351
  • 15
  • 74
  • 97

4 Answers4

56

This has nothing to do with IIS7 Express and everything to do with the fact that you're using loopback traffic.

Ref: https://www.fiddlerbook.com/fiddler/help/hookup.asp#Q-LocalTraffic

Click Rules > Customize Rules.

Update your Rules file like so:

static function OnBeforeRequest(oSession:Fiddler.Session)
{
    if (oSession.HostnameIs("MYAPP")) { oSession.host = "localhost:portnumber"; }
}

Then, just visit http://myapp in your browser.

Or use the address http://localhost.fiddler/ and Fiddler will use the hostname localhost instead of converting to an IP address.

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
EricLaw
  • 56,563
  • 7
  • 151
  • 196
  • I read that and it doesn't work. I assume this is because IIS7 Express only listens on localhost – Brettski Jan 16 '11 at 18:08
  • 4
    Hi Eric and Brettski, Brettski is correct, I have actually found the same issue with IIS Express. It seems to only monitor the hostname "localhost" not traffic to 127.0.0.1. I have had a similar issue that I posted about on StackOverflow recently http://stackoverflow.com/questions/4709014/using-custom-domains-with-iis-express – Nick Berardi Jan 17 '11 at 00:20
  • 1
    Apparently it has to be running under Admin Rights and you have to go in and modify the bindings. I don't understand why any of this is necessary since Cassini easily does this. Why can't IIS Express just monitor the port on 127.0.0.1 without a "localhost" host header. – Nick Berardi Jan 17 '11 at 00:55
  • 1
    Sigh. I wish they'd make up their minds. You can easily use the FiddlerScript on that page: OnBeforeRequest. Edited answer. – EricLaw Jan 17 '11 at 18:00
  • Eric, me too. There is no reason to have this type of binding in IIS in my oppinion. "*:1234:localhost" Because it means it is listening on all IP addresses for a host header that comes through as "localhost". I am hoping since you are a softy that you can bring this to the attention of the right people because the binding should actually be "127.0.0.1:1234:" so that any host header pointing to the localhost can be used. – Nick Berardi Jan 17 '11 at 19:31
  • @Eric I was able to bind to 127.0.0.1 by changing the binding information in the applicationhost.config file (my documents\IISExpress\config\\) Didn't matter for Fiddler though as I was still not able to get it to work – Brettski Jan 21 '11 at 04:10
  • This actually worked out great. The one item I needed to change is to add a port number to localhost. The part I like best about this is that http://localhost:nnnn opens outside of fiddler and changing the url to http://myapp sends to fiddler. Thank you for the fix – Brettski Jan 21 '11 at 04:29
  • I would recommend the following modification that would make the port selection possible from the url itself. // workaround the iisexpress limitation if (oSession.HostnameIs("app")) { oSession.host = "localhost:"+oSession.port; } – Jaro Dunajsky Jan 21 '11 at 08:30
  • @Eric: not really concerned about IPv6 at this time, and I think it is a little early for them to start worrying about it given the huge usability problems their current bindings cause. However they could just double bind the site, "127.0.0.1:1234:" and "::1:1234:" if they really wanted to support both. The fact that it is currently locked down to the host header "localhost" is a huge problem and currently the only way to get around it in VS is to change bindings manually and run VS as Admin, not doable in many corporate environments. And a real PITA for large teams using source control. – Nick Berardi Jan 21 '11 at 14:45
12

One useful variation of Eric's answer (that was edited by Brett) would be to use oSession.port to build the oSession.host. With this little change, if one needs to capture IIS express traffic on http://localhost:12345, they could use http://iisexpress:12345. That will make it easier to capture traffic for sites with random ports as created by WebMatrix and VS. I tried it out with IE and Firefox and capturing IIS Express traffic was a breeze. Fiddler rocks!.

static function OnBeforeRequest(oSession:Fiddler.Session)
{
   //...
   // workaround the iisexpress limitation
   // URL http://iisexpress:port can be used for capturing IIS Express traffic
   if (oSession.HostnameIs("iisexpress")) { oSession.host = "localhost:"+oSession.port; }
   //...
}
Liam
  • 27,717
  • 28
  • 128
  • 190
Jaro Dunajsky
  • 2,003
  • 14
  • 8
  • You might also want to add this: `oSession.utilReplaceInResponse("localhost:" + oSession.port, "iisexpress:" + oSession.port);` – Gebb Jul 25 '13 at 09:31
5

With the latest version of fiddler, you only need to navigate to localhost.fiddler:port. However, doing that alone didn't help me and I was still getting access denied when using Windows Authentication. To fix this, I found this blog entry: http://www.parago.de/2013/01/fiddler-and-the-401-unauthorized-error-with-asp-net-web-api-using-integrated-windows-authentication-wia/

In short, create this key:

Key Path HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Control\Lsa\MSV1_0

Value Name BackConnectionHostNames

Value Type REG_MULTI_SZ

String Value localhost.fiddler

Thraka
  • 2,065
  • 19
  • 24
0

You can use fiddler as a proxy between your clients and the server. This means you start up fiddler, and then access the server using fiddler's port rather then the usual port (default for fiddler2 is 8888 I think). If you need to debug the server "live" vs. real world clients, you can change the IIS binding from :80 to something else, and place fiddler's proxy on port 80.

EDIT: By the way, by default fiddler2 changes the proxy settings on your browsers so that they access everything through fiddler anyway (on the machine in which fiddler is installed only)

sinelaw
  • 16,205
  • 3
  • 49
  • 80