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
Server.MapPath()的用法的更多相关文章
- asp于Server.MapPath用法
总是忘记Server.MapPath的用法,以下记录了,以后使用: 总注:Server.MapPath获得的路径都是server上的物理路径,也就是常说的绝对路径 1.Server.MapPath(& ...
- Asp.Net Server.MapPath()用法
做了一个上传文件的功能 本地测试没问题 部署到服务器之后 一直报错 由于 某些历史原因 看不到错误信息 最后发现是路径的问题 其实这么简单的问题 最早该想到的 ...... Server.MapPat ...
- Server.mappath用法
1.Server.MapPath ("/") 应用程序根目录所在的位置 如 C:\qq\qqroot\ 2.Server.MapPath ("./") 表示所在 ...
- Server.MapPath() 用法
Server.MapPath() ./当前目录/网站主目录../上层目录~/网站虚拟目录 如果当前的网站目录为E:\wwwroot 应用程序虚拟目录为E:\wwwroot\company 浏览的页 ...
- Server.MapPath 的使用方法
Server.MapPath 的使用方法 用法: 1.Server.MapPath ("/") 应用程序根目录所在的位置 如 C:\Inetpub\wwwroot\ 2.Serve ...
- How can I use Server.MapPath() from global.asax?
引用: using System.Web.Hosting; string filePathcsv = ""; string file = ""; string ...
- Server.MapPath()
./当前目录/网站主目录../上层目录~/网站虚拟目录 如果当前的网站目录为E:\wwwroot 应用程序虚拟目录为E:\wwwroot\company 浏览的页面路径为E:\wwwroot\co ...
- Server.MapPath和Request.PhysicalApplicationPath的异同
很多人对它们都不陌生,在众多的WEB程序中,使用Server.MapPath和Request.PhysicalApplicationPath来操作目录/文件的几率参半,我曾经也经常混用,然而时间久了. ...
- Server.MapPath查询路径那几件事
主要总结Server.MapPath 这个方法的使用以及使用的场景,不是什么时候都适合使用: 1.实现功能: Server.MapPath能够获取指定URL相对服务器的物理路径,在IIS服务端,能够根 ...
随机推荐
- error_reporting()函数
定义和用法 error_reporting() 函数跪地你给应该报告何种 PHP 错误. error_reporting() 函数能够在运行时设置 error_reporting 指令. PHP 有诸 ...
- ajax发送请求的数据类型
1.如果要传给后台的是json形式的数据 2.如果要传给后台的是formdata形式的数据
- last-child到底怎么用
今天工作时候遇到的坑, 看来还是css基础不够扎实,特此记录一下, <div> <p>1</p> <p>2</p> <p>3&l ...
- Raspberry Pi - 调整你的SD卡分割区的大小
在使用Win32DiskImager为一张空白的SD卡刷入新的Rasbian系统后,卡上的可用剩余空间并不大, 本人有一张8G的SD卡,但是刷入4.1的Rasbian后,用df -h查看,根目录下的空 ...
- Ehcache学习总结(2)--Ehcache整合spring配置
首先需要的maven依赖为: [html] view plain copy <!--ehcache--> <dependency> <groupId>com.goo ...
- rsyslog学习
http://blog.csdn.net/zhaoyangjian724/article/details/52116809 http://blog.csdn.net/zhangxihangzhuan/ ...
- Python 调用snmp自定义OID实现监控
http://kkkkkk.blog.51cto.com/468162/1172726 http://blog.csdn.net/mirahs/article/details/49619729
- Android 使用DrawerLayout高速实现側滑菜单
一.概述 DrawerLayout是一个能够方便的实现Android側滑菜单的组件,我近期开发的项目中也有一个側滑菜单的功能.于是DrawerLayout就派上用场了.假设你从未使用过DrawerLa ...
- xcode 4 svn配置(host is unreachable)
xcode 4 svn配置 先保证你的xcode中已经安装了command line tools xcode -> preferences -> downloads -> comma ...
- 九度OJ 1070 今年的第几天?(模拟)
题目1070:今年的第几天? 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3491 解决:1936 题目描写叙述: 输入年.月.日,计算该天是本年的第几天. 输入: 包含三个整数年(1& ...