Howdy, Stranger!

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


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

Jeson84Jeson84 USAMember Posts: 90

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



  • DavidMDavidM USAMember Posts: 342

    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.