asp.net file path to get the virtual directory of the web site's root directory
- 2020-05-17 05:16:29
- OfStack
string Server.MapPath(string path)
Returns the physical file path corresponding to the specified virtual path on the Web server.
Server. MapPath (Request. ServerVariables [" PATH_INFO "])
Server. MapPath ("/")
Server. MapPath (" ")
Server. MapPath (". ")
Server. MapPath (".. / ")
Server. MapPath (".." )
Page.Request.ApplicationPath
(HttpContext.Current.Request.PhysicalApplicationPath);
The above code in http: / / localhost EnglishClub manage/WebForm1 aspx page
Operation results:
C: \ Inetpub \ wwwroot \ EnglishClub \ manage \ WebForm1 aspx
C: \ Inetpub \ wwwroot \
C: \ Inetpub \ wwwroot \ EnglishClub \ manage
C: \ Inetpub \ wwwroot \ EnglishClub \ manage
C: \ Inetpub \ wwwroot \ EnglishClub \
C: \ Inetpub \ wwwroot \ EnglishClub
C: \ Inetpub \ wwwroot \ EnglishClub \
As can be seen from the above:
To get the root directory of a web site with a virtual directory created, use the following:
Server.MapPath(Page.Request.ApplicationPath)
Returns the physical file path corresponding to the specified virtual path on the Web server.
Server. MapPath (Request. ServerVariables [" PATH_INFO "])
Server. MapPath ("/")
Server. MapPath (" ")
Server. MapPath (". ")
Server. MapPath (".. / ")
Server. MapPath (".." )
Page.Request.ApplicationPath
(HttpContext.Current.Request.PhysicalApplicationPath);
The above code in http: / / localhost EnglishClub manage/WebForm1 aspx page
Operation results:
C: \ Inetpub \ wwwroot \ EnglishClub \ manage \ WebForm1 aspx
C: \ Inetpub \ wwwroot \
C: \ Inetpub \ wwwroot \ EnglishClub \ manage
C: \ Inetpub \ wwwroot \ EnglishClub \ manage
C: \ Inetpub \ wwwroot \ EnglishClub \
C: \ Inetpub \ wwwroot \ EnglishClub
C: \ Inetpub \ wwwroot \ EnglishClub \
As can be seen from the above:
To get the root directory of a web site with a virtual directory created, use the following:
Server.MapPath(Page.Request.ApplicationPath)