C# – Visual Studio/ Asp.net / IIS Pathing Help

asp.netciisiis-7url

I am having some serious pathing issues with a website that I am creating. I am using Visual Studio 2008 IDE with IIS7 on Windows Vista Home Premium. This is a website project and not an asp.net web application (according to Visual Studio).

Well here is the problem. I am using IIS 7 as a test server, even though VS 2008 has its own built-in web-server. On a previous website that I created I used VS 2008 test server and all was fine and dandy, but this project I am strictly using IIS 7. I am getting pathing issues galore. For example

http://localhost/mywebsite/default.aspx

Whenever I try to access the root of the site, like

<a href="/default.aspx" />

It goes to "http://localhost/", and thus, there is an error. And this really screws things up when I try to map items on the server-side code

Server.MapPath("/"); //Will not work in this configuration

I vaguely remember something in visual studio about setting the start root path, but I'm not exactly sure where to set this and/or if their is this option. I'm not sure if there is a configuration change needed on IIS 7, or in Visual Studio.

Also, to set up a website on IIS (with Visual Studio), I created a new website and set the location on my localhost (HTTP) and virtual directories. Did I set this up correctly?

Best Answer

<a href="~/default.aspx" runat="server" />

Thanks to the runat="server" tag, the framework will now resolve it correctly.