首页 > 移动平台 > 详细

[转载]Server.MapPath和Request.MapPath()的用法

时间:2019-12-16 14:39:16      阅读:104      评论:0      收藏:0      [点我收藏+]

Server.MapPath和Request.MapPath()的用法

转载自:https://blog.csdn.net/blocksom/article/details/7785570

 
./当前目录 
/根目录 
../上层目录(相对当前来说) 
如果当前的网站目录为D:\wwwroot    浏览的页面路径为D:\wwwroot\company\news\show.asp 
在show.asp页面中使用
Server.MapPath("./")   返回路径为:D:\wwwroot\company\news 
Server.MapPath("/")    返回路径为:D:\wwwroot 
Server.MapPath("../")   返回路径为:D:\wwwroot\company 
server.MapPath(request.ServerVariables("Path_Info")) 
Request.ServerVariables("Path_Translated")   
上面两种方式返回路径为 D:\wwwroot\company\news\show.asp 


ASP.NET中Server.MapPath() 和 Request.MapPath()区别: 
Server.MapPath(string)   :是将相对于当前调用文件的文件(或目录)映射为物理路径; 
Request.MapPath(string) :是将string虚拟路径映射为物理路径(asp中Request无此方法) 
Server.MapPath(string) 中string 可以用“../”方式引用父目录,甚至可以将此目录跳到整个WEB目录外,如:C:\WWWROOT 
目录为WEB根目录,在根目录文件中调用此Server.MapPath("../xyz.gif"),则可以调用WEB目录外的脚本、资源等。 
Request.MapPath(string) 中的string为虚拟目录,只能相对WEB虚拟目录形式的,也不允许"../"方式调用,只能是"/","/xx"等字符串 
有时候直接用Server.MapPath(string) 调用一个文件比较麻烦,因为不同的目录中调用同一个Server.MapPath(string) 函数就会得到不同的值, 
特殊的话,就需要通过判断本身目录层次才能获取正确的地址,使用的Request.MapPath(string)就可以调用同一个目录文件。不用做目录判断

[转载]Server.MapPath和Request.MapPath()的用法

原文:https://www.cnblogs.com/hx215267863/p/12048880.html

(0)
(0)
   
举报
评论 一句话评论(0
分享档案
最新文章
教程昨日排行
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!