1.    Server.MapPath("/")  应用程序根目录所在的位置 如

C:\Inetpub\wwwroot\

2.Server.MapPath("./")  表示所在页面的当前目录 
      注:等价于Server.MapPath("")  返回 Server.MapPath("")所在页面的物理文件路径
      3.Server.MapPath("../")表示上一级目录 
      4.Server.MapPath("~/")表示当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置如:   

C:\Inetpub\wwwroot\Example\
     注:等效于Server.MapPath("~"),即相对路径

Java代码 :
string filename=Server.MapPath("./") + @"\Web.config";   
string filename=Server.MapPath("./") + "/Web.config";   
string filename=Server.MapPath("") + @"\Web.config"  

string filename=Server.MapPath("./") + @"\Web.config";

string filename=Server.MapPath("./") + "/Web.config";

string filename=Server.MapPath("") + @"\Web.config"

string Server.MapPath(string path)
返回与Web服务器上的指定虚拟路径相对应的物理文件路径。

Html代码 
<%=Server.MapPath(Request.ServerVariables["PATH_INFO"])%>  
  
<%= Server.MapPath("/")%>  
<%= Server.MapPath("")%>  
<%=Server.MapPath(".")%>  
  
<%= Server.MapPath("../")%>  
<%= Server.MapPath("..")%>  

<%=Server.MapPath(Request.ServerVariables["PATH_INFO"])%> 

<%= Server.MapPath("/")%>

<%= Server.MapPath("")%>

<%=Server.MapPath(".")%> 

<%= Server.MapPath("../")%>

<%= Server.MapPath("..")%> 
以上的代码在http://localhost/EnglishClub/manage/WebForm1.aspx页面
运行结果:
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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
猜你喜欢
  • 2021-09-08
  • 2021-11-30
  • 2021-11-27
  • 2021-08-10
  • 2022-01-10
  • 2021-09-04
  • 2022-02-15
相关资源
相似解决方案