Server.MapPath() in ASP.NET


Introduction and Demonstration

Many times we need to know the full path of remote server where we are hosting files or the exact location of file exist on file server. We have MapPath method which maps the specified relative or virtual path to the corresponding physical directory on the web server/file server. Usually any web server never allows to access in any path if we don't have proper permission. Even we can't list the directories or file as we list in DOS like 
 

Above image includes the file and director list of my development server, the same we can't do with production server remotely. Although, we can find our file location on hosting server/production server remotely as given below: 
  

I have used following codes for this: 

protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Server.MapPath("."));
        Response.Write("<br>");
        Response.Write(Server.MapPath(""));
        Response.Write("<br>");
        Response.Write(Server.MapPath("~"));
    }

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System