获取用户在浏览器中输入的确切 url [英] Get the exact url the user typed into the browser
问题描述
我想获取用户在浏览器中输入的确切网址.当然,我总是可以使用诸如 Request.Url.ToString()
之类的东西,但是在以下情况下,这并没有给我想要的东西:
I would like to get the exact url that user typed into the browser. Of course I could always use something like Request.Url.ToString()
but this does not give me what i want in the following situation:
http://www.mysite.com/rss
使用上面的 url Request.Url.ToString()
会给我的是:
With the url above what Request.Url.ToString()
would give me is:
http://www.mysite.com/rss/Default.aspx
有谁知道如何做到这一点?
Does anyone know how to accomplish this?
我已经试过了:
Request.Url
Request.RawUrl
this.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 的行为不同(请参阅密钥文档).
You want the HttpWorkerRequest.GetServerVariable()
with the key HTTP_URL
or CACHE_URL
. Note that the behavior differs between IIS 5 and IIS 6 (see documentation of the keys).
为了能够访问所有服务器变量(如果你得到null
),直接访问HttpWorkerRequest:
In order to be able to access all server variables (in case you get null
), directly access the HttpWorkerRequest:
HttpWorkerRequest workerRequest =
(HttpWorkerRequest)((IServiceProvider)HttpContext.Current)
.GetService(typeof(HttpWorkerRequest));
这篇关于获取用户在浏览器中输入的确切 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!