Getting current page URL (or it’s parts) in C#

Here is an easy reference for how to get different parts of an URL in C#.

I’ve color-coded the example URL below for easier matching with the values of the properties of the HttpRequest.

URL used for this example:

Value of HttpContext.Current.Request.Url.Host

Value of HttpContext.Current.Request.Url.Authority

Value of HttpContext.Current.Request.Url.AbsolutePath

Value of HttpContext.Current.Request.ApplicationPath

Value of HttpContext.Current.Request.Url.AbsoluteUri

Value of HttpContext.Current.Request.RawUrl

Value of HttpContext.Current.Request.Url.PathAndQuery

This entry was posted in Work and tagged , , , , , . Bookmark the permalink.

3 Responses to Getting current page URL (or it’s parts) in C#

  1. good reference!
    from time to time our developers forget the difference between development url’s with webdev server and production url’s with iis.

  2. Rabab says:

    Thanks , it helped me a lot 🙂

  3. Abdul Muttalib says:

    I there any way to get only “q1=1&q2=2” — from HttpContext.Current.Request.

Leave a Reply

Your email address will not be published. Required fields are marked *