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
|
|