网站建设对企业影响有多大,坪山做网站,免费seo,免费咨询医生有问必答http://blog.csdn.net/qiuhaifeng_csu/article/details/19416407 Server.MapPath(string path)作用是返回与Web服务器上的指定虚拟路径相对应的物理文件路径。其参数path为Web 服务器的虚拟路径#xff0c;返回结果是与path相对应的物理文件路径。但有时参数并非为虚拟路径返回结果是与path相对应的物理文件路径。但有时参数并非为虚拟路径而是用户自定义的文件名。 Server.MapPath()的全名是System.Web.HttpContext.Current.Server.MapPath()。有时在程序调试时会提示“当前上下文中不存在名称“Server””错误从而不支持函数Server.MapPath()的使用。尽管引用了命名空间“using System.Web;”也是无济于事此时就需要使用其全名或者是当前使用Server.MapPath()函数的类继承自System.Web.UI.Page。 Server.MapPath() 返回当前页面所在的物理文件路径 Server.MapPath(/) 返回应用程序根目录所在的物理文件路径 Server.MapPath(./) 返回当前页面所在的物理文件路径 Server.MapPath(../)返回当前页面所在的上一级的物理文件路径 Server.MapPath(~/)返回应用程序的虚拟目录路径 Server.MapPath(~)返回应用程序的虚拟目录路径 说明对于Server.MapPath()具体返回什么内容在不同的环境下得到的结果也许并不相同。 用法1.Server.MapPath(/) 应用程序根目录所在的位置 如 C:\Inetpub\wwwroot\ 2.Server.MapPath(./) 表示所在页面的当前目录 注等价于Server.MapPath() 返回 Server.MapPath()所在页面的物理文件路径 3.Server.MapPath(../)表示上一级目录 4.Server.MapPath(~/)表示当前应用级程序的目录 Server.MapPath(~) /Content/Data/LeftMenu.xml; D:\\Project\\TMS2012\\TMSWeb 如果是根目录就是根目录 如果是虚拟目录就是虚拟目录所在的位置 如C:\Inetpub\wwwroot\Example\ 注等效于Server.MapPath(~)。 当前的网站目录为E:\wwwroot 应用程序虚拟目录为E:\wwwroot\company 浏览的页面路径为E:\wwwroot\company\news\show.asp 在show.asp页面中使用 Server.MapPath(./) 返回路径为E:\wwwroot\company\news Server.MapPath(/) 返回路径为E:\wwwroot Server.MapPath(../) 返回路径为E:\wwwroot\company Server.MapPath(~/) 返回路径为E:\wwwroot\company server.MapPath(request.ServerVariables(Path_Info)) Request.ServerVariables(Path_Translated) 上面两种方式返回路径为 D:\wwwroot\company\news\show.asp转载于:https://www.cnblogs.com/ZkbFighting/p/8399997.html