目前我正在尝试获取浏览器中显示的当前 URL。
如果我用
Request.Path
我得到 https://this.website.com:443/Default.aspx这在技术上是正确的。
但是浏览器本身显示的 URL 是 https://this.website.com/ .
使用任何请求选项仍然会显示 Default.aspx。
我需要最终检测浏览器中的 url 是否为 https://this.website.com或 http://this.website.com/Default.aspx然后重定向到 Default.aspx(如果不存在)。
顺便说一句,让事情变得更复杂的是我的 web.config 中的 https 重定向。
请您参考如下方法:
你可以从httpcontext中的请求中得到它.
HttpContext.Current.Request.Url
更新:
如果你想知道当前 url 是/还是/default.aspx。您可以使用 RawUrl请求的属性。该字段将包含整个 url。
HttpContext.Current.Request.RawUrl
