Van*_*ith 8 c# asp.net url request
我想获得用户输入浏览器的确切网址.当然我总是可以使用类似的东西,Request.Url.ToString()但在下列情况下,这并没有给我我想要的东西:
http://www.mysite.com/rss
上面的url Request.Url.ToString()会给我的是:
http://www.mysite.com/rss/Default.aspx
有谁知道如何做到这一点?
我已经尝试过了:
Request.UrlRequest.RawUrlthis.Request.ServerVariables["CACHE_URL"]this.Request.ServerVariables["HTTP_URL"]((HttpWorkerRequest)((IServiceProvider)HttpContext.Current).GetService(typeof(HttpWorkerRequest))).GetServerVariable( "CACHE_URL")((HttpWorkerRequest)((IServiceProvider)HttpContext.Current).GetService(typeof(HttpWorkerRequest))).GetServerVariable( "HTTP_URL")编辑:您想要HttpWorkerRequest.GetServerVariable()使用密钥HTTP_URL或CACHE_URL.请注意,IIS 5和IIS 6之间的行为有所不同(请参阅密钥文档).
为了能够访问所有服务器变量(如果你得到null),直接访问HttpWorkerRequest:
HttpWorkerRequest workerRequest =
(HttpWorkerRequest)((IServiceProvider)HttpContext.Current)
.GetService(typeof(HttpWorkerRequest));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7218 次 |
| 最近记录: |