views:

136

answers:

4

Hey guys,

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?

+1  A: 

try

Server.MapPath("~/");
John Boker
+1  A: 
<a href="~/default.aspx" runat="server" />

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

IrishChieftain
A: 

You can override the app root path on the Web tab of the project settings, if this is a web site or Web Application Project. However, this only tells Visual Studio how to resolve the ~ at design/compile time. You really want to use the tilde everywhere to refer to the root of your app. That way it will work seamlessly whether it's a web site in IIS or runs as a virtual directory.

Bryan
+3  A: 

When creating links or referencing URIs in ASP .NET keep the following in mind.

  • The tilde character "~/" represents the root of the application.

  • The forward slash "/" represents the absolute root of the URI.

When dealing with an application in a virtual directory, the application root will be the path to that virtual directory. If you want your links to start at the application root, always prefix them with ~/. If you need to link to the root of the URI you can simply use the forward slash /.

Dan