How to get current page URL in ASP.NET

To get the current page URL you could use HttpContext.Current.Request.Url:

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

string absoluteurl = HttpContext.Current.Request.Url.AbsoluteUri;
// http://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