Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 892211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:01:00+00:00 2026-05-15T14:01:00+00:00

I have had a real nightmare with Server.MapPath() . When I call Server.MapPath(~) in

  • 0

I have had a real nightmare with Server.MapPath(). When I call Server.MapPath("~") in my application that is running in ASP.NET Development Server it returns root directory that ends in a back slash like f:\projects\app1\, but I call it in published version, installed in IIS, it returns root directory without any back slash like c:\inetpub\wwwroot\app1. Why this happens? How could avoid?

I did 2 scenarios on a same machine: Windows Server 2008 R2 x64, Visual Studio 2010 x64, IIS 7.

UPDATE:

Why I care about it? Ineed I have wrote a custom site map provider based on file/folder structure. It extracts list of file/folders of root directory "~", replaces root directory section with Server.MapPath("~") in order to generate URL of .aspx files for use in ASP.NET Menu control. I think following code explains what I’m doing:

    string mainRoot = HttpContext.Current.Server.MapPath("~");

    DirectoryInfo di = new DirectoryInfo(mainRoot); 

    //added to solve this problem with Server.MapPath
    if (!mainRoot.EndsWith(@"\"))
        mainRoot += @"\";


    FileInfo[] files = di.GetFiles("*.aspx");
    foreach (FileInfo item in files)
    {
        string path = item.FullName.Replace(mainRoot, "~/").Replace(@"\", "/");

        //do more here
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:01:00+00:00Added an answer on May 15, 2026 at 2:01 pm

    It could be from when you set up the virtual directory inside of IIS, depending on whether you used a trailing slash when setting it up.

    But does it really matter? Why would you even care what Server.MapPath("~") returns? I can’t imagine you’d ever use it just like that. Much more likely is when you actually need a path to something inside your application:

    Server.MapPath("~/Something/Foo.txt");
    

    In addition, whenever you build up paths, you should try to get into the habit of using Path.Combine, because you don’t need to worry about trailing slashes at all then:

    string fullPath = Path.Combine(Server.MapPath("~"), @"Something\Foo.txt");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.