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. Canvas DrawImage截取和压缩图片的陷阱

    html5的canvas十分之强大,可以做到快速的截取压缩出新的图片! 不过最近开发过程中遇到一个问题,图片压缩后使用toDataURL取得图片显示为一片漆黑,什么都没有! 折腾了很久,起初以为是上传 ...

  2. 关于VC++中virtual ~的含义

    我知道virtual 的虚函数定义,~CMainFrame( )是析构函数,用来释放内存.C++的继承和派生内容.所有可以被用作基类的类一般都用虚析构函数当基类对象的指针或引用调用派生类对象时,如果基 ...

  3. /dev/shm 引起的内存统计问题

    最近,有个同事问我,怎么准确地描述linux系统到底还有多少内存可供我使用.这里不扯内存碎片问题,就说剩余总量. 如下: cat /proc/meminfo MemTotal: 263796812 k ...

  4. SuperMap iClient for JavaScript初入

    SuperMap iClient for JavaScript初入 介绍SuperMap for Js的简单使用. 推荐先看下这篇文档:SuperMap iClient for JavaScript ...

  5. lua版本的一个状态机

    这个状态机http://www.cnblogs.com/flytrace/p/5587033.html的lua版本 -- LUA 有实现枚举值的好办法么 local sc_enum = { -- ev ...

  6. AngularJS执行流程详解(转)

    一.启动阶段 大家应该都知道,当浏览器加载一个HTML页面时,它会将HMTL页面先解析成DOM树,然后逐个加载DOM树中的每一个元素节点.我们可以把AngularJS当做一个类似jQuery的js库, ...

  7. C之多线程(例子很不错)

    1.线程 线程池是一个树状结构. 多线程解决并发问题. 一个线程内部的执行顺序是线性的.而线程之间是乱序的. 若要创建一个多线程程序,它的参数必须是空指针类型. 变色龙程序: #define _CRT ...

  8. Django REST framework中的版本控制

    1.REST framework版本控制的流程分析 1.1 determine_version方法的执行流程 首先,请求到达REST framework的CBV,执行CBV中的dispatch方法再次 ...

  9. Sonar 常用代码规则整理(二)

    摘要:公司部署了一套sonar,经过一段时间运行,发现有一些问题出现频率很高,因此有必要将这些问题进行整理总结和分析,避免再次出现类似问题. 作者原创技术文章,转载请注明出处 ============ ...

  10. 浅谈PHP异常处理

    1.PHP中异常的独特性 PHP中的异常的独特性,即PHP中的异常不同于主流语言C++.java中的异常.在Java中,异常是唯一的错误报告方式,而在PHP中却不是这样,而是把所有不正常的情况都视作了 ...