Server.MapPath in ASP.NET, ASPX, MVC, MVC 3 and NET Framework.
Server.MapPath specifies the relative or virtual path to map to a physical directory.
1. Server.MapPath(“.”) returns the current physical directory of the file (e.g. aspx) being executed
2. Server.MapPath(“..”) returns the parent directory
3. Server.MapPath(“~”) returns the physical path to the root of the application
4. Server.MapPath(“/”) returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)
An example:
Let’s say you pointed a web site application (http://www.example.com/) to
C:\Inetpub\wwwroot
and installed your shop application (sub web as virtual directory in IIS, marked as application) in
D:\WebApps\shop
For example, if you call Server.MapPath in following request:
http://www.example.com/shop/products/GetProduct.aspx?id=2342
then:
1. Server.MapPath(“.”) returns D:\WebApps\shop\products
2. Server.MapPath(“..”) returns D:\WebApps\shop
3. Server.MapPath(“~”) returns D:\WebApps\shop
4. Server.MapPath(“/”) returns C:\Inetpub\wwwroot
5. Server.MapPath(“/shop”) returns D:\WebApps\shop