简体   繁体   中英

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.

If I use

Request.Path 

I get https://this.website.com:443/Default.aspx which is technically correct.

However the URL displayed in the browser itself is https://this.website.com/ .

Using any of the Request options still will show 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.

Btw complicating things more is the https redirect in my web.config.

You can get it from the request in the httpcontext .

HttpContext.Current.Request.Url

Updated:

If you want to tell wether the current url is / or /default.aspx. You can use the RawUrl property of the request. This field will contain the whole url.

HttpContext.Current.Request.RawUrl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM