Search code examples
asp.netvisual-studioiisvisual-studio-2012iis-7.5

Why is a Web Site project not serving pages except through IIS?


I have inherited quite a complex web site project, and when I run it in VS 2012 under the default "Use default Web server" setting for "Server", it serves the login page correctly, under the base URL http://localhost:45632 and I can log in nicely. Then, when I click a menu item with the URL http://localhost:45632/Apps/Visitors/General.aspx, I get a good and plain 404.

If I then create a web site (not application under the default site) for it in IIS 7.5; set the physical directory to the project's source folder; give it a host name, xtjethro.local, and edit my hosts file to point that host name to 127.0.0.1; set the web site project to use a custom server, with a base URL of and finally, browse the site from its context menu, it serves its pages under the base url http://xtjethro.local/ instead of http://localhost:45632, everything works fine.

Then, if I set the web site project to use a custom server with a base URL of http://xtjethro.local, and restart VS2012, running it as administrator, everything works from there as well.

I would like to know why http://localhost:45632/Apps/Visitors/General.aspx doesn't work under VS2012, but http://xtjethro.local/Apps/Visitors/General.aspx does work under IIS.


Solution

  • The Visual Studio development web-server usually runs the site under a virtual directory which matches your project name. That would mean that the URL of your page should be http://localhost:45632/YourProjectName/Apps/Visitors/General.aspx. If you create an application under the default site in IIS, you will probably see the same problem.

    You'll need to change the way your links are generated. Instead of using /Apps/..., use ~/Apps/... - ASP.NET will automatically resolve ~/ to the base path of the site.