[1230online] 壹贰叁零科技在线

标题: ASP.NET用Server.MapPath()获取路径的方法 [打印本页]

作者: 夏穆SUMMUR    时间: 2016-3-1 11:21
标题: ASP.NET用Server.MapPath()获取路径的方法
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











欢迎光临 [1230online] 壹贰叁零科技在线 (http://www.1230online.com/) Powered by Discuz! X3.2