Getting the current URL that is shown in the browser

asp.net, c#, request, url

Solution

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

Problem

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.

Original source

Related problems