Monday, February 25, 2019

Server.MapPath

Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?

Server.MapPath specifies the relative or virtual path to map to a physical directory.

Server.MapPath(".")1 returns the current physical directory of the file (e.g. aspx) being executed
Server.MapPath("..") returns the parent directory
Server.MapPath("~") returns the physical path to the root of the application
Server.MapPath("/") returns the physical path to the root of the domain name
 (is not necessarily the same as the root of the application)

Server.MapPath(".")1 returns D:\WebApps\Site\DemoProducts
Server.MapPath("..") returns D:\WebApps\Site
Server.MapPath("~") returns D:\WebApps\Site
Server.MapPath("/") returns C:\Inetpub\wwwroot
Server.MapPath("/Site") returns D:\WebApps\Site


1) Server.MapPath(".") -- Returns the "Current Physical Directory" of the file (e.g. aspx) being executed.

Ex. Suppose  D:\WebApps\Site\DemoProducts

2) Server.MapPath("..") -- Returns the "Parent Directory"

Ex. D:\WebApps\Site

3) Server.MapPath("~") -- Returns the "Physical Path to the Root of the Application"

Ex. D:\WebApps\Site

4) Server.MapPath("/") -- Returns the physical path to the root of the Domain Name

Ex. C:\Inetpub\wwwroot

No comments:

Post a Comment