Development: Interesting issue with Server.MapPath

On September 3, 2006, in Development, by Mitch Milam

I was working on my site transition and developing the download code when I ran into a very interesting issue while using the Development Web Server that is built into Visual Studio 2005.

Consider the following code:

string rootDir = Server.MapPath(@"~\downloads");
string rootDir2 = Server.MapPath(@"..\downloads");

 

If you are running on the development web server, the second command will fail with a message: Failed to map the path.

However, if you deploy and run the same code to a real IIS server, you will receive the following correct values back:

d:\hosting\files\test\downloads
d:\hosting\files\downloads

I am going to make an assumption that this issue is related to the way in which the Development Web Server is actually creating the virtual web server. 

 

 

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>