How to get the URL of the current page in C#

apekshabs picture apekshabs · Feb 27, 2009 · Viewed 1.1M times · Source

Can anyone help out me in getting the URL of the current working page of ASP.NET in C#?

Answer

Canavar picture Canavar · Feb 27, 2009

Try this :

string url = HttpContext.Current.Request.Url.AbsoluteUri;
// http://localhost:1302/TESTERS/Default6.aspx

string path = HttpContext.Current.Request.Url.AbsolutePath;
// /TESTERS/Default6.aspx

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