Knowledge found and lost while working with Microsoft Dynamics CRM
RSS icon Home icon
  • Development: Interesting issue with Server.MapPath

    Posted on September 3rd, 2006 Mitch Milam Print Print No comments

    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. 

     

    Development
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    994 views