Server.MapPath()的用法
http://blog.csdn.net/qiuhaifeng_csu/article/details/19416407
Server.MapPath(string path)作用是返回与Web服务器上的指定虚拟路径相对应的物理文件路径。其参数path为Web 服务器的虚拟路径,返回结果是与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
Server.MapPath()的用法相关推荐
- Server.MapPath(path)的使用
用法: 1.Server.MapPath("/") 应用程序根目录所在的位置 如 C:\Inetpub\wwwroot\ 2.Server.MapPath("./&quo ...
- server.mappath 与page命名空间说明
一 .Server.MapPath的命名空间: 习惯用Access的朋友都知道:ADO.NET链接Access数据库经常这么写: strcon="Provider=Microsoft.J ...
- Server.MapPath() 探究
Server.MapPath(path) The MapPath method maps the specified relative or virtual path to the co ...
- asp.net .ashx文件使用server.mappath解决方法
本人试过多种方法,均不可用,最后灵光一动,为何不能人引用的命名空间入手了,以下是解决方法,经本人验证. System.Web.HttpContext.Current.Server.MapPath 给同 ...
- server.mapPath(.mdb)
server.mapPath(".mdb") 用http://www.google.com搜索server.mapPath(".mdb"),可以得到很多采用ac ...
- Server.MapPath()目录详解
最近在做相关的开发,碰到了Server.MapPath(),顺便来温习一下 Server.MapPath()获取网站的目录详解 ./当前目录 /网站主目录 ../上层目录 ~/网站虚拟目录 如果当前 ...
- ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath、Server.MapPath的区别...
1.Request.ApplicationPath->当前应用的目录 Jsp中, ApplicationPath指的是当前的application(应用程序)的目录,ASP.NET中也是这 ...
- 引用到网站绝对路径Server.MapPath(~/myfile.mdb)
在任何路径下,都可以用Server.MapPath("~/")引用到网站根目录下 转载于:https://www.cnblogs.com/yurichou/archive/2005 ...
- ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath、Server.MapPath的区别
ASP.NET中Request.ApplicationPath.Request.FilePath.Request.Path..Request.MapPath.Server.MapPath的区别 1.R ...
最新文章
- Java 必须掌握的 20+ 种 Spring 常用注解
- python函数的唯一标识_python基础教程Python通用唯一标识符uuid模块使用案例
- POJ 1170 Shoping Offers(IOI 95)
- Linux下如何让自己的程序在开机时自动启动
- 7-26晚上实现mystring
- LUA和C#关于字符串中\0的处理
- vue移动端项目缓存问题实践
- Nova 组件详解 - 每天5分钟玩转 OpenStack(26)
- 自己动手写TCC7901的GPIO驱动
- 【华为出品】物联网全栈开发实战营第2期来啦!送海思开发板
- MySQL in 查询,并通过 FIELD 函数按照查询条件顺序返回结果
- Java 对Oracle数据库中的 BLOB类型 插入图片
- 管理感悟:减少代码量的好办法
- IPD在华为成功的6个原因
- 微信小程序在手机上预览时出现白屏
- 2021年P气瓶充装模拟考试及P气瓶充装考试试题
- 秦九韶算法与霍纳规则
- 自动化测试设计模之PO(PageObject)
- python毕业设计课题-毕业设计:爬虫及数据分析
- 微信小程序图片显示模式
热门文章
- atom编写python程序_编写我们的第一个Python程序,print.py
- Spring框架中的单例Bean是线程安全的吗
- EasyExcel导入的时候报错Caused by: java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/File
- 自定义注解,aop实现注解锁
- python class函数报错_Python multiprocess pool模块报错pickling error问题解决方法分析
- 为今天的光纤检测选择光纤示波器
- 如何避免重复请求/并发请求?这样处理才足够优雅
- 连接maven_如何在Eclipse中使用Maven工程连接远程的Spark
- java类型比较_java 基本数据类型 ==和equals()比较
- html5 保存 搜索历史,html5 – 如何有效处理Dart中的浏览器历史记录(即后退按钮)?...