一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Server.MapPath方法的应用方法

时间:2011-06-19 编辑:简简单单 来源:一聚教程网

Server.MapPath方法的应用方法

总注:Server.MapPath获得的路径都是服务器上的物理路径,也就是常说的绝对路径
1、Server.MapPath("/")
注:获得应用程序根目录所在的位置,如 C:Inetpubwwwroot。
2、Server.MapPath("./")
注:获得所在页面的当前目录,等价于Server.MapPath("")。
3、Server.MapPath("../")
注:获得所在页面的上级目录。
4、Server.MapPath("~/")
注:获得当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置,如C:InetpubwwwrootExample。

 

./当前目录
/网站主目录
../上层目录
~/网站虚拟目录

如果当前的网站目录为E:wwwroot   应用程序虚拟目录为E:wwwrootcompany 浏览的页面路径为E:wwwrootcompanynewsshow.asp教程
在show.asp页面中使用
Server.MapPath("./")   返回路径为:E:wwwrootcompanynews
Server.MapPath("/")    返回路径为:E:wwwroot
Server.MapPath("../")   返回路径为:E:wwwrootcompany
Server.MapPath("~/")   返回路径为:E:wwwrootcompany
server.MapPath(request.ServerVariables("Path_Info"))
Request.ServerVariables("Path_Translated") 
上面两种方式返回路径为 D:wwwrootcompanynewsshow.asp

 

热门栏目