当前位置:编程学习 > C#/ASP.NET >>

asp.net 文件路径之获得虚拟目录的网站的根目录

答案:string Server.MapPath(string path)
  返回与Web服务器上的指定虚拟路径相对应的物理文件路径。
  Server.MapPath(Request.ServerVariables["PATH_INFO"])

   Server.MapPath("/")
   Server.MapPath("")
  Server.MapPath(".")
   Server.MapPath("../")
   Server.MapPath("..") 
Page.Request.ApplicationPath
(HttpContext.Current.Request.PhysicalApplicationPath);

  以上的代码在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

  C:\Inetpub\wwwroot\EnglishClub\
由以上可以知道:
要想获得要是建立的虚拟目录的网站的根目录可以这样使用:
Server.MapPath(Page.Request.ApplicationPath)

上一个:asp.net中Post表单保存页面状态并输出源码的实现方法
下一个:精通ASP.NET中弹出窗口技术

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,