[英]Getting the current URL that is shown in the browser
Currently I'm trying to get the current URL that is shown in the browser. 目前,我正在尝试获取浏览器中显示的当前URL。
If I use 如果我用
Request.Path
I get https://this.website.com:443/Default.aspx which is technically correct. 我得到https://this.website.com:443/Default.aspx ,这在技术上是正确的。
However the URL displayed in the browser itself is https://this.website.com/ . 但是,浏览器本身显示的URL是https://this.website.com/ 。
Using any of the Request options still will show Default.aspx. 使用任何“请求”选项仍将显示Default.aspx。
I need to ultimately detect wether or not the url in the browser is https://this.website.com or http://this.website.com/Default.aspx and then redirect to Default.aspx if it's not there. 我最终需要确定浏览器中的URL是否为https://this.website.com或http://this.website.com/Default.aspx ,然后重定向到Default.aspx(如果不存在)。
Btw complicating things more is the https redirect in my web.config. 令事情更加复杂的是我的web.config中的https重定向。
You can get it from the request in the httpcontext . 您可以从httpcontext中的请求中获取它。
HttpContext.Current.Request.Url
Updated: 更新:
If you want to tell wether the current url is / or /default.aspx. 如果您想告诉我们当前的URL是/或/default.aspx。 You can use the RawUrl property of the request. 您可以使用请求的RawUrl属性。 This field will contain the whole url. 该字段将包含整个网址。
HttpContext.Current.Request.RawUrl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.