找回密码
 注册
搜索
打印 上一主题 下一主题

[NET] ASP.NET用Server.MapPath()获取路径的方法

[复制链接]
跳转到指定楼层
楼主
夏穆SUMMUR 发表于 2016-3-1 11:21:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ASP.NET用Server.MapPath()获取路径的方法,符号用法比较微妙。


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


如果当前的网站目录为E:\SUMMUR.COM   
应用程序虚拟目录为E:\SUMMUR.COM\company
浏览的页面路径为E:\SUMMUR.COM\company\news\1230.aspx


在1230.aspx页面中使用时,


Server.MapPath("./") 返回路径为:E:\SUMMUR.COM \company\news
Server.MapPath("/") 返回路径为:E:\SUMMUR.COM
Server.MapPath("../") 返回路径为:E:\SUMMUR.COM \company
Server.MapPath("~/") 返回路径为:E:\SUMMUR.COM \company


同样在ASP中,
server.MapPath(request.ServerVariables("Path_Info"))
Request.ServerVariables("Path_Translated")  
这两种方式返回路径为 E:\SUMMUR.COM \company\news\1230.asp






夏穆中文网|SUMMUR.COM
快速回复 返回顶部 返回列表