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. 关于IDE与环境变量的一点说明

    环境变量就是当计算机要执行操作时,在环境变量所制定的范围内查找该操作. 比如linux的ls命令,计算机就需要在$PATH规定的目录中寻找该ls的可执行文件. java的classpath,在该规定的 ...

  2. javaScript中关于字符串的操作函数和方法

    1.字符串转换 toString():可以将任何类型的数据都转换为字符串 var num= 19; //19 var myStr = num.toString(); //"19" ...

  3. OpenGL+OpenCV实现立方体贴图

    我屮艸芔茻,转眼就7月份了. 今天试了一下立方体贴图,比较简单,大概说下和平面贴图的区别. 1. 平面贴图需要的是纹理坐标vec2:立方体贴图需要的是一个方向向量vec3,长度没有关系,重要的是方向, ...

  4. 为什么alertView弹出后button会消失的问题

    按option后会有提示:Do not use the label object to set the text color or the shadow color. Instead, use the ...

  5. JVM核心之JVM运行和类加载全过程

    为什么研究类加载全过程? 有助于连接JVM运行过程 更深入了解java动态性(解热部署,动态加载),提高程序的灵活性 类加载机制 JVM把class文件加载到内存,并对数据进行校验.解析和初始化,最终 ...

  6. Ajax常用实例

    摘录自:http://www.cnblogs.com/gaopeng527/p/4459622.html 1. 级联下拉列表 例1.1 级联下拉列表. (1)编写AjaxRequest.js文件,并将 ...

  7. 自己动手搭建一个简易的SpringBoot环境

    什么是springboot? Spring Boot俗称微服务.Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特 ...

  8. char,varchar,nvarchar,text区别与联系

    CHAR,NCHAR 定长,速度快,占空间大,需处理VARCHAR,NVARCHAR,TEXT 不定长,空间小,速度慢,无需处理NCHAR.NVARCHAR.NTEXT处理Unicode码

  9. 2017-07-09(tar who last)

    tar gzip ,bzip2对于文件目录压缩支持有限,所以出现了tar命令 tar [选项]  打包文件名  源文件 -c 打包 -v 显示过程 -f 指定打包文件名 -x 解包 -z 压缩成.ta ...

  10. mysql主从同步(3)-percona-toolkit工具(数据一致性监测、延迟监控)使用梳理

    转自:http://www.cnblogs.com/kevingrace/p/6261091.html 在mysql工作中接触最多的就是mysql replication mysql在复制方面还是会有 ...