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()的用法的更多相关文章

  1. asp于Server.MapPath用法

    总是忘记Server.MapPath的用法,以下记录了,以后使用: 总注:Server.MapPath获得的路径都是server上的物理路径,也就是常说的绝对路径 1.Server.MapPath(& ...

  2. Asp.Net Server.MapPath()用法

    做了一个上传文件的功能 本地测试没问题 部署到服务器之后 一直报错 由于 某些历史原因 看不到错误信息 最后发现是路径的问题 其实这么简单的问题 最早该想到的 ...... Server.MapPat ...

  3. Server.mappath用法

    1.Server.MapPath ("/") 应用程序根目录所在的位置 如 C:\qq\qqroot\ 2.Server.MapPath ("./") 表示所在 ...

  4. Server.MapPath() 用法

    Server.MapPath() ./当前目录/网站主目录../上层目录~/网站虚拟目录 如果当前的网站目录为E:\wwwroot   应用程序虚拟目录为E:\wwwroot\company 浏览的页 ...

  5. Server.MapPath 的使用方法

    Server.MapPath 的使用方法 用法: 1.Server.MapPath ("/") 应用程序根目录所在的位置 如 C:\Inetpub\wwwroot\ 2.Serve ...

  6. How can I use Server.MapPath() from global.asax?

    引用: using System.Web.Hosting; string filePathcsv = ""; string file = ""; string ...

  7. Server.MapPath()

    ./当前目录/网站主目录../上层目录~/网站虚拟目录 如果当前的网站目录为E:\wwwroot   应用程序虚拟目录为E:\wwwroot\company 浏览的页面路径为E:\wwwroot\co ...

  8. Server.MapPath和Request.PhysicalApplicationPath的异同

    很多人对它们都不陌生,在众多的WEB程序中,使用Server.MapPath和Request.PhysicalApplicationPath来操作目录/文件的几率参半,我曾经也经常混用,然而时间久了. ...

  9. Server.MapPath查询路径那几件事

    主要总结Server.MapPath 这个方法的使用以及使用的场景,不是什么时候都适合使用: 1.实现功能: Server.MapPath能够获取指定URL相对服务器的物理路径,在IIS服务端,能够根 ...

随机推荐

  1. 最标准的 Java MySQL 连接

    package com.runoob.test; import java.sql.*; public class MySQLDemo { // JDBC 驱动名及数据库 URL static fina ...

  2. Vuejs componet

    Vuejs  componet <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...

  3. php时间戳转化成时间相差8小时问题

    php时间戳 转化成时间的时候 $mytime=time(); echo $mytime.'<br />'; echo date('Y-m-d H:i:s',$mytime); 会产生8个 ...

  4. url链接打开本地应用(测试通过)

    基于windows!! 类比mailto://XXXX 主要参考: https://www.cnblogs.com/snow365/p/6428212.html 应用 1.在网页上本地办公 网页应用越 ...

  5. hibernate session.save()和session.persist()的区别

    save()需要返回一个Serialzable的实现类,因此执行这个方法时会马上插入到数据库 而persist()不会立即插入到数据库. "当我们封装一个长会话流程的时候,persist() ...

  6. 网络载入数据和解析JSON格式数据案例之空气质量监測应用

    一.创建一个新的项目 activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res ...

  7. [Python] Indexing An Array With Another Array with numpy

    NumPy Reference: Indexing Integer array indexing: Select array elements with another array def index ...

  8. JAVA类库LinkList的基本实现

    写完调试了好久,边界不优点理,具体的请看JDK类库,下面仅仅是基本实现: import java.util.Iterator; /** * 类名:MyLinkedList 说明:LinkedList的 ...

  9. vue3事件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Haproxy压测

    目的:测试Haproxy压测情况 环境: Ha服务器:8核16G虚机,后端6个2核4G,压测客户端3个2核4G 安装和优化: 一.Haproxy #cd /opt/soft #wget http:// ...