What is the correct way to get the URL of the current page in C#?

Please explain how to get the URL of the current working page of ASP.NET in C#


  • Use one of the following as required.

    string url = HttpContext.Current.Request.Url.AbsoluteUri;
    // http://localhost:port/FOLDER/FILE_NAME.aspx
    string path = HttpContext.Current.Request.Url.AbsolutePath;
    // /FOLDER/FILE_NAME.aspx
    string host = HttpContext.Current.Request.Url.Host;
    // localhost
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion