How to get current page URL in ASP.NET


1. To get the full URL with query string (if any) you could use:

string absoluteurl = HttpContext.Current.Request.Url.AbsoluteUri;
// https://localhost:80/test/Default.aspx?test=1

2. To get the path without the domain you could use:

string absolutepath = HttpContext.Current.Request.Url.AbsolutePath;
// /test/Default.aspx

3. To get the Host:

string host = HttpContext.Current.Request.Url.Host;
// localhost