VS2008 and web application - hostname

Recently I ran into an issue where IIS was refusing to load an otherwise previously perfectly good web application in the solution.

The Visual Studio 2008 solution included a Web Application csproj, and was referencing it by URL on IIS (that is, not a local file based or Cassini web project). Attempting to load the solution brought up an error:

The local IIS URL http://localhost/{YourAppName} specified for Web Project {YourAppName} has not been configured. In order to open this project the Virtual Directory needs to be configured. Would you like to create the Virtual Directory now?

First, checked the IIS manager and ensured application pool and web site were up and operational. All seemingly well.

Since my web application was in fact a WCF web service, I first tried to access the WSDL: It worked. A WSDL was returned, so I knew the web application was operational or at the very least reachable.

Finally I looked more closely at IIS. Clicking the “Web Sites” folder itself brings up a grid on the right. It shows the web site name, port, IP and state. Sorting by Port, I noticed several web sites were running on 80. The way it works is that one of them had no host headers at all, and the rest had a host header, thereby distinguishing them from the rest of the web sites on the same port.

Normally, I do this when working on several web applications and wanting to mimic production as closely as possible without the need for multiple IPs on the dev box. At some point, I installed MOSS and used the dev box’s WINS name (the name of the machine in AD) as the host header name.

The confusion became clear when looking more closely at the WSDL returned. Although the IP I used was

http://localhost/{MyAppName} , the WSDL link rendered was

http://MyMachineName/{MyAppName}?WSDL ..

This clued in on the answer:

IIS setup for Sharepoint

Created a c:\windows\system32\drivers\etc\hosts entry SomeName for the IIS web site which previously was using the machine name as a hosts header, changed IIS so that the host header for the offending site was using the new entry and things are back to normal.