服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

asp.net Request获取url信息的各种方法比较

2019-07-15 10:00asp.net之家 ASP.NET教程

本页地址: Request.URL; 上页地址: 复制代码 代码如下: Request.UrlReferrer Request.ServerViables[http_referer] Request.RawUrl Request.RawUrl.QueryAndPath System.IO.Path.GetFileName(Request.FilePath.ToString()) 在ASP.NET编程中经常需要用Request获取url的有关信息,Request中有

本页地址: Request.URL; 
上页地址: 

复制代码代码如下:


Request.UrlReferrer 
Request.ServerViables["http_referer"] 
Request.RawUrl 
Request.RawUrl.QueryAndPath 
System.IO.Path.GetFileName(Request.FilePath.ToString()) 


在ASP.NET编程中经常需要用Request获取url的有关信息,Request中有多种方法获取 url信息,但我经常忘了各种方法的具体作用,今天我就写了个测试程序,将各种方法得到的结果列出来,以后用时直接参考一下就行了。 
测试的url 地址是http://www.test.com/testweb/default.aspx, 结果如下: 

复制代码代码如下:


Request.ApplicationPath: /testweb 
Request.CurrentExecutionFilePath: /testweb/default.aspx 
Request.FilePath: /testweb/default.aspx 
Request.Path: /testweb/default.aspx 
Request.PathInfo: 
Request.PhysicalApplicationPath: E:\WWW\testweb\ 
Request.PhysicalPath: E:\WWW\testweb\default.aspx 
Request.RawUrl: /testweb/default.aspx 
Request.Url.AbsolutePath: /testweb/default.aspx 
Request.Url.AbsoluteUri: http://www.test.com/testweb/default.aspx 
Request.Url.Host: www.test.com 
Request.Url.LocalPath: /testweb/default.aspx 


当url中带参数时可以使用: 
HttpContext.Current.Request.Url.PathAndQuery.ToString()

延伸 · 阅读

精彩推荐