Server.MapPath with usage of . , .. , ~ and / Characters in ASP.NET

Published on October 2, 2014 by abundantcode

Filed under ASP.NET

Last modified October 2, 2014

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3579 times

When using Server.MapPath in ASP.NET, the developers can specify the characters as shown below.

var path1 = Server.MapPath(“.”)
var path2 = Server.MapPath(“..”)
var path3 = Server.MapPath(“~”)
var path4 = Server.MapPath(“/”)

What is the difference between the above methods ?

Assume that the website is installed in the path D:\WebApplications\Abundantcode and the root of the IIS is C:\Inetpub\wwwroot and assume that the current page is http://abundantcode.com/popularposts

The path1 will contain D:\WebApplications\Abundantcode\popularposts which is the current physical directory of the file

Path 2 will contain D:\WebApplications\Abundantcode\ which is the parent directory

Path 3 will contain D:\WebApplications\Abundantcode\ which is the physical path of the root of the application.

Path 4 will contain C:\Inetpub\wwwroot which is root of the domain name.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to return Json instead of XML in ASP.NET Web API ?

When you make a call to the ASP.NET Web API action method and notice this in Google Chrome browser ,...

How to Add Web API to existing ASP.NET Web Forms Project ?

In one of the previous posts , we saw how to add the WebAPI to the existing ASP.NET MVC project. Wel...

How to Add Web API to existing ASP.NET MVC Project ?

There are times when you might want to add Web API project to one of your existing ASP.NET MVC proje...