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

2021-05-15 13:01

阅读:468

标签:包括   size   project   htm   介绍   操作   cat   getdir   info   

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

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的各个属性对应的意义介绍

标签:包括   size   project   htm   介绍   操作   cat   getdir   info   

原文地址:http://www.cnblogs.com/xytmj/p/7753323.html


评论


亲,登录后才可以留言!