Howdy, Stranger!

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

Categories

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

Jeson84Jeson84 USAPosts: 90Member

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

Tagged:

Comments

  • DavidMDavidM USAPosts: 342Member

    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.