得到确切的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
通过上面什么 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]
- <$c$c>((HttpWorkerRequest)((IServiceProvider)HttpContext.Current).GetService(typeof(HttpWorkerRequest))).GetServerVariable( CACHE_URL)
- <$c$c>((HttpWorkerRequest)((IServiceProvider)HttpContext.Current).GetService(typeof(HttpWorkerRequest))).GetServerVariable( HTTP_URL)
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")
推荐答案
编辑:您想要的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.httpworkerrequest.getservervariable.aspx\"><$c$c>HttpWorkerRequest.GetServerVariable()$c$c>用钥匙 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).
为了能够访问所有服务器变量(如果你得到空
),直接访问的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屋!