使用Server.Mappath(QUOT;&QUOT),使用Server.Mappath(QUOT;〜&QUOT),使用Server.Mappath(@" \\&QUOT),使用Server.Mappath(QUOT; /&QUOT)。有什么不同? [英] Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?

查看:391
本文介绍了使用Server.Mappath(QUOT;&QUOT),使用Server.Mappath(QUOT;〜&QUOT),使用Server.Mappath(@" \\&QUOT),使用Server.Mappath(QUOT; /&QUOT)。有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释(。),使用Server.Mappath 使用Server.Mappath之间的差值(〜)使用Server.Mappath(@\\)使用Server.Mappath(/)

推荐答案

使用Server.Mappath 指定的相对或虚拟路径映射以物理目录

Server.MapPath specifies the relative or virtual path to map to a physical directory.


  • 使用Server.Mappath(。) 1 返回正在执行的文件的当前物理目录(如C ++)

  • 使用Server.Mappath(..)返回上一级目录

  • 使用Server.Mappath(〜)返回给应用程序
  • 的根的物理路径
  • 使用Server.Mappath(/)返回到域名的根目录的物理路径(不一定是相同的应用程序的根目录)

  • Server.MapPath(".")1 returns the current physical directory of the file (e.g. aspx) being executed
  • Server.MapPath("..") returns the parent directory
  • Server.MapPath("~") returns the physical path to the root of the application
  • Server.MapPath("/") returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)

一个例子:

让我们说你指出一个网站的应用程序( http://www.example.com/ ),以

Let's say you pointed a web site application (http://www.example.com/) to

C:\Inetpub\wwwroot

D:\WebApps\shop

例如,如果你调用中使用Server.Mappath以下要求:

For example, if you call Server.MapPath in following request:

http://www.example.com/shop/products/GetProduct.aspx?id=2342

然后


  • 使用Server.Mappath(。) 1 收益 D:\\ WebApps的\\店\\产品

  • 使用Server.Mappath(..)收益 D:\\ WebApps的\\店

  • 使用Server.Mappath(〜)收益 D:\\ WebApps的\\店

  • 使用Server.Mappath(/)收益 C:\\的Inetpub \\ wwwroot文件

  • 使用Server.Mappath(/店)收益 D:\\ WebApps的\\店

  • Server.MapPath(".")1 returns D:\WebApps\shop\products
  • Server.MapPath("..") returns D:\WebApps\shop
  • Server.MapPath("~") returns D:\WebApps\shop
  • Server.MapPath("/") returns C:\Inetpub\wwwroot
  • Server.MapPath("/shop") returns D:\WebApps\shop

如果路径的开头或者是向前( / )或反斜杠( \\ ),MapPath方法返回仿佛是路径一个完整的虚拟路径的路径。

If Path starts with either a forward (/) or backward slash (\), the MapPath method returns a path as if Path were a full, virtual path.

如果路径不以斜线开始,则MapPath方法返回相对于正在处理的请求的目录的路径。

If Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the request being processed.

注意:在C#,@是逐字字符串字面意思运营该字符串应该用原样和转义序列不会被处理

脚注


  1. 使用Server.Mappath(空)使用Server.Mappath()会的产生这种效果太

  1. Server.MapPath(null) and Server.MapPath("") will produce this effect too.

这篇关于使用Server.Mappath(QUOT;&QUOT),使用Server.Mappath(QUOT;〜&QUOT),使用Server.Mappath(@" \\&QUOT),使用Server.Mappath(QUOT; /&QUOT)。有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆