Localhost doesn't work? Can't debug your .Net web app? This may be your answer.

For my very first post I’d like to share the solution to a problem I solved a month or two ago, but it was such a pain in the ass I’m certain someone will find this post useful.

When you run the debugger in Microsoft Visual Studio .Net 2003 & 2005 for a website project, by default Visual Studio opens up your site in a new web browser using the localhost path. Unfortunately for me, my localhost path was hosed for, what was then, some unknown reason. So when I clicked the debug button my browser would look for a few minutes for the site, then give me a page not found error. Along with this failure to find the page, while my browser was looking, my CPU utilization was running at 100%!

To get around this problem in Visual Studio 2003 I would simple start the debugger, and then as soon as my browser window opened, I clicked Stop. I then typed in my computers IP address in place of localhost in the address bar, and the browser would then happily find my website. This worked fine in 2003 because it relied on IIS to host my developing web application.

Unfortunately this solution did not work when I migrated to Visual Studio 2005. By default when you debug a web application in 2005, the site is opened in a virtual IIS web server. So my old tricks didn’t work. Now unable to debug my web apps I had to find the solution to my original problem. Why isn’t my localhost working?

I was able to ping my machine name, my IP address, localhost, and even 127.0.0.1. My Host file was untainted and correct. I even tried altering the Host file to make localhost point to my IP address. I could access websites in IIS using every address method EXCEPT localhost!

So I remoted into a development box I knew localhost worked on. I then ran IPCONFIG on that box and my own. Then I tried to make the results of my IPCONFIG identical to the computer that worked.

I noticed my computer had a lot of extra crap in the IPCONFIG that looked something like this:

c:\>ipconfig
Windows IP Configuration
Ethernet adapter Ethernet:
 Connection-specific DNS Suffix  . : wcoast.corp.example.com
 IP Address. . . . . . . . . . . . : 157.54.139.57
 Subnet Mask . . . . . . . . . . . : 255.255.252.0
 IP Address. . . . . . . . . . . . : 3ffe:ffff:8311:f282:1460:5260:c9b1:fda6
 IP Address. . . . . . . . . . . . : 3ffe:ffff:8311:f282:b973:4db8:97e2:e978
 IP Address. . . . . . . . . . . . : 3ffe:ffff:8311:f282:200:39ff:fe0e:fc35
 IP Address. . . . . . . . . . . . : fec0::f282:200:39ff:fe0e:fc35%1
 IP Address. . . . . . . . . . . . : fe80::200:39ff:fe0e:fc35%4
 Default Gateway . . . . . . . . . : 157.54.136.1
                                            fe80::210:ffff:fed6:58c0%4
Tunnel adapter 6to4 Tunneling Pseudo-Interface:
 Connection-specific DNS Suffix  . : wcoast.corp.example.com
 IP Address. . . . . . . . . . . . : 2002:9d3b:8b39::9d3b:8b39
 Default Gateway . . . . . . . . . :
Tunnel adapter Automatic Tunneling Pseudo-Interface:
 Connection-specific DNS Suffix  . : wcoast.corp.example.com
 IP Address. . . . . . . . . . . . : fec0::f70f:0:5efe:157.54.139.57%1
 IP Address. . . . . . . . . . . . : 3ffe:ffff:8311:f70f:0:5efe:157.54.139.57
 IP Address. . . . . . . . . . . . : fe80::5efe:157.54.139.57%2
 Default Gateway . . . . . . . . . : fe80::5efe:157.56.253.8%2

I googled some of the strange IP addresses then I learned about IPv6.

IPv6 is a new IP address protocol that basically gives us more addresses than IPv4. As the internet grows we’re gradually running out of available IP addresses IPv6 is the solution. IPv6 snuck onto my computer at some point during a Windows update. This is all well and good but for some reason it was killing my localhost path! After I uninstalled it, WHALAH! Localhost started working again, and I could properly debug my web apps in Visual Studio 2005.

To remove ipv6 in Windows XP with SP2, Windows XP with SP1, or Windows Server 2003 go to Control Panel -> Network Connections then double click the network card / adaptor you’re using. Under “This connection uses the following items” section you should see “Microsoft IPv6 Developer Edition” or “Microsoft TCP/IP version 6”. Select it and click uninstall.

If that doesn’t work, or you have Windows XP with no service pack installed, try running “netsh interface ipv6 uninstall” or “ipv6 uninstall” in Windows command prompt. Then go patch your OS!

If anyone knows why IPv6 was killing my localhost path, or you know how to have IPv6 installed and keep localhost working, I’d love to hear from you.

Happy debugging.

References:
IPv6 for Microsoft Windows: Frequently Asked Questions

12 Replies to “Localhost doesn't work? Can't debug your .Net web app? This may be your answer.”

  1. I had a similar problem – I had a .net application that during the install would prompt the user for the machine name where a SQL instance was located: the default is “localhost”.

    My issue ended up being as simple as the IP address for my DNS servers had changed and I didn’t know it. Once I the TCP/IP properties for my machine with the new IP address for DNS, the application I was testing started working again.

    I do have to say thank you for your post – because it sent me down the path to check this.

    Thanks!

  2. cheers folks, after now looking to make asp.net upgrades and VS2003 to VS2005 this was looking to be a pain in the a, the commenting out of localhost in hosts file solved, such a simple result.

    thanks again

Leave a Reply

Your email address will not be published. Required fields are marked *