Asp.net中Request.Url的各个属性对应的意义介绍

本文转载自 http://www.jb51.net/article/30254.htm

网络上关于Request.Url的说明已经很多也很丰富了,但是自己还是实践了一下,看看最终的结果与网络上的是否一致
 
1.简单的环境搭建 
  在本地IIS上配置了一个网站:主机名为wjnhome.com,端口88,然后建了一个虚拟目录指向同一站点,虚拟目录名称为virtual,配置host为127.0.0.1  wjnhome.com 
  所以地址就为:http://jb51.net:88/virtual/urldemo.aspx?id=2#top 
2.编写简单的代码


//虚拟目录的路径 
Response.Write("<strong>Request.ApplicationPath:</strong>" + Request.ApplicationPath + "</br>"); 
//站点的物理路径(完整路径) 
Response.Write("<strong>Request.PhysicalPath:</strong>" + Request.PhysicalPath + "</br>"); 
//站点物理路径的目录 
Response.Write("<strong>DirectoryName:</strong>" + System.IO.Path.GetDirectoryName(Request.PhysicalPath) + "</br>"); 
//站点物理路径的目录 
Response.Write("<strong>Request.PhysicalApplicationPath:</strong>" + Request.PhysicalApplicationPath + "</br>"); 
//当前页面的文件名 
Response.Write("<strong>FileName:</strong>" + System.IO.Path.GetFileName(Request.PhysicalPath) + "</br>"); 
//当前页面的虚拟路径 
Response.Write("<strong>Request.CurrentExecutionFilePath:</strong>" + Request.CurrentExecutionFilePath + "</br>"); 
//当前页面的虚拟路径 
Response.Write("<strong>Request.FilePath:</strong>" + Request.FilePath + "</br>"); 
Response.Write("<strong>Request.Path:</strong>" + Request.Path + "</br>"); 
//原始URL 
Response.Write("<strong>Request.RawUrl:</strong>" + Request.RawUrl + "</br>"); 
//绝对路径(不包括参数什么的) 
Response.Write("<strong>Request.Url.AbsolutePath:</strong>" + Request.Url.AbsolutePath + "</br>"); 
//绝对URL 
Response.Write("<strong>Request.Url.AbsoluteUri:</strong>" + Request.Url.AbsoluteUri + "</br>"); 
//URL协议方案 
Response.Write("<strong>Request.Url.Scheme:</strong>" + Request.Url.Scheme + "</br>"); 
//URL的主机名 
Response.Write("<strong>Request.Url.Host:</strong>" + Request.Url.Host + "</br>"); 
//URL端口号 
Response.Write("<strong>Request.Url.Port:</strong>" + Request.Url.Port + "</br>"); 
//主机名+端口号 
Response.Write("<strong>Request.Url.Authority:</strong>" + Request.Url.Authority + "</br>"); 
//获取文件名的本地操作系统表现形式 
Response.Write("<strong>Request.Url.LocalPath:</strong>" + Request.Url.LocalPath + "</br>"); 
//附加路径信息,例如http://jb51.net:88/UrlDemo.aspx/Hello?id=22#top 那么这里就是Hello 
Response.Write("<strong>Request.PathInfo:</strong>" + Request.PathInfo + "</br>"); 
//URL的路径和GET参数 
Response.Write("<strong>Request.Url.PathAndQuery:</strong>" + Request.Url.PathAndQuery + "</br>"); 
//URL的GET参数 
Response.Write("<strong>Request.Url.Query:</strong>" + Request.Url.Query + "</br>"); 
//主要指的是http://jb51.net:88/UrlDemo.aspx/Hello?id=22#top中#后面的top。 
//但一般情况下无法获取值,因为浏览器不会把这个值发送到服务器端 
Response.Write("<strong>Request.Url.Fragment:</strong>" + Request.Url.Fragment + "</br>"); 
//主机名 
Response.Write("<strong>Request.Url.DnsSafeHost:</strong>" + Request.Url.DnsSafeHost + "</br>"); 
//URL的全部 
Response.Write("<strong>Request.Url.OriginalString:</strong>" + Request.Url.OriginalString + "</br>"); 
//这种情况 Uri uriAddress = new Uri ("http://user:password@www.contoso.com/index.htm ") Console.WriteLine(uriAddress.UserInfo); 
Response.Write("<strong>Request.Url.UserInfo:</strong>" + Request.Url.UserInfo + "</br>"); 
//从某个页面跳转过来的时候会显示源页面的值 
Response.Write("<strong>Request.UrlReferrer:</strong>" + Request.UrlReferrer + "</br>"); 
//URI的每一段 
for (var i = 0; i < Request.Url.Segments.Length;i++ ) 

Response.Write("<strong>Request.Url.Segment" + i + ":</strong>" + Request.Url.Segments[i] + "</br>"); 

3.输出结果 
  Request.ApplicationPath:/virtual 
  Request.PhysicalPath:E:\VsProject\201200420\UrlDemo\UrlDemo\urldemo.aspx 
  DirectoryName:E:\VsProject\201200420\UrlDemo\UrlDemo 
  Request.PhysicalApplicationPath:E:\VsProject\201200420\UrlDemo\UrlDemo\ 
  FileName:urldemo.aspx 
  Request.CurrentExecutionFilePath:/virtual/urldemo.aspx 
  Request.FilePath:/virtual/urldemo.aspx 
  Request.Path:/virtual/urldemo.aspx 
  Request.RawUrl:/virtual/urldemo.aspx?id=2 
  Request.Url.AbsolutePath:/virtual/urldemo.aspx 
  Request.Url.AbsoluteUri:http://jb51.net:88/virtual/urldemo.aspx?id=2 
  Request.Url.Scheme:http 
  Request.Url.Host:wjnhome.com 
  Request.Url.Port:88 
  Request.Url.Authority:wjnhome.com:88 
  Request.Url.LocalPath:/virtual/urldemo.aspx 
  Request.PathInfo: 
  Request.Url.PathAndQuery:/virtual/urldemo.aspx?id=2 
  Request.Url.Query:?id=2 
  Request.Url.Fragment: 
  Request.Url.DnsSafeHost:wjnhome.com 
  Request.Url.OriginalString:http://jb51.net:88/virtual/urldemo.aspx?id=2 
  Request.Url.UserInfo: 
  Request.UrlReferrer: 
  Request.Url.Segment0:/ 
  Request.Url.Segment1:virtual/ 
  Request.Url.Segment2:urldemo.aspx 

Asp.net中Request.Url的各个属性对应的意义介绍的更多相关文章

  1. 转载MSDN 在ASP.NET 中执行 URL 重写

    转载文章原网址 http://msdn.microsoft.com/zh-cn/library/ms972974.aspx 摘要:介绍如何使用 Microsoft ASP.NET 执行动态 URL 重 ...

  2. asp.net中Request.ServerVariables的用法

    在asp.net中可以通过HttpRequest.ServerVariables 属性来获取“ Web 服务器变量的集合” HttpRequest.ServerVariables 的用法: HttpR ...

  3. ASP.NET中Request.RawUrl、Request.Url的区别

    如果访问的地址是: http://hovertree.com/guestbook/addmessage.aspx?key=hovertree%3C&n=myslider#zonemenu 那么 ...

  4. ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath、Server.MapPath(转载)

    1.Request.ApplicationPath->当前应用的目录   Jsp中, ApplicationPath指的是当前的application(应用程序)的目录,ASP.NET中也是这个 ...

  5. ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath、

    1.Request.ApplicationPath->当前应用的目录    Jsp中, ApplicationPath指的是当前的application(应用程序)的目录,ASP.NET中也是这 ...

  6. ASP.NET 中Request.QueryString 中的key

    在ASP.net中 的Key是可能为null的,例如在如下的Url中 http://localhost:14546/Home/Index?a 有一个key=null 其value是a,以前一直以为ke ...

  7. ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath

    1.Request.ApplicationPath->当前应用的目录 2.Request.FilePath->对应于iis的虚拟目录   如 URL http://mockte.com/1 ...

  8. 关于ASP.NET中Request.QueryString的乱码问题(转)

    转自 http://www.cnblogs.com/chinhr/archive/2008/09/23/1296582.html 今天在使用Request.QueryString的时候,发现所有接收到 ...

  9. asp.net中C#对象与方法 属性详解

    C#对象与方法 一.相关概念: 1.对象:现实世界中的实体 2. 类:具有相似属性和方法的对象的集合 3.面向对象程序设计的特点:封装  继承 多态 二.类的定义与语法 1.定义类: 修饰符 类名称 ...

随机推荐

  1. CentOS如何把deb转为rpm

    说明:可以转换,但不一定可用,可以根据报错提示,安装需要的依赖. 1 安装alien工具,下载地址http://ftp.de.debian.org/debian/pool/main/a/alien/ ...

  2. Apache Shiro java安全框架

    什么是Apache Shiro? Apache Shiro(发音为“shee-roh”,日语“堡垒(Castle)”的意思)是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理功能,可为 ...

  3. keytool 错误:java.to.FileNotFoundException:

    老是报如题的错误: 后来才知道是因为当前的目录下没有写的权限,所以需要指定一个路径来存放android.key: keytool -genkey -alias android.key -keyalg ...

  4. 【转】wget

    wget 下载整个网站,或者特定目录 需要下载某个目录下面的所有文件.命令如下 wget -c -r -np -k -L -p www.xxx.org/pub/path/ 在下载时.有用到外部域名的图 ...

  5. angular4在prod模式下的JIT编译问题

    最近利用angular4开发一个项目,由于画面中的显示都是从数据表中读取,通过设置显示FLAG和显示顺序对画面布局按既定规则控制的, 所以必须利用动态编译实现. 方法如下, 1,获取JitCompil ...

  6. SQL explain详细结果

    explain 的结果 id select_type 查询的序列号 select_type simple (不含子查询) primary (含子查询.或者派生查询) subquery (非from子查 ...

  7. 01_Linux安装

    一.VMware创建一个虚拟机 下一步   .下一步  .下一步 ..前方高能 二.安装CentOS 6.7 next  ->  选择 中文简体  -> 美式键盘,直接下一步  ,一直下一 ...

  8. 只用120行Java代码写一个自己的区块链

    区块链是目前最热门的话题,广大读者都听说过比特币,或许还有智能合约,相信大家都非常想了解这一切是如何工作的.这篇文章就是帮助你使用 Java 语言来实现一个简单的区块链,用不到 120 行代码来揭示区 ...

  9. rapid framework开发系列(一)

    定义:web项目脚手架 rapid-framework是一个以spring为核心的项目脚手架(或者称为胶水框架),框架将各个零散的框架(struts,strust2,springmvc,hiberna ...

  10. iOS-生成二维码图片【附中间带有小图标二维码】(QRCode)

    生成二维码图片也是项目中常用到的,二维码的扫描Git上有很多好用的,这里主要说下二维码的生成 1.普通二维码 方法 /** 生成二维码 QRStering:字符串 imageFloat:二维码图片大小 ...