<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1742770185958071&amp;ev=PageView&amp;noscript=1">

Inbound Marketing Blog

Request.URL & What's That Property?

Request.URL can be used in .NET to get the value that the web browser used to access a page. However, there are many different properties to choose from, and sometimes it is difficult to know which property to use.

I tired of guessing at the correct value and decided to write a small bit of code to display all of the properties so I could find the correct value faster next time.

Here’s what my code looks like:


Imports System.Reflection

Partial Class Tests_requestURL
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim info() As PropertyInfo = Request.Url.GetType().GetProperties()
        For Each a As PropertyInfo In info
            If a.CanRead Then
                Me.ltlValues.Text &amp;= String.Format(&quot;{0}: {1}&lt;br&gt;&lt;br&gt;&quot;, a.Name, a.GetValue(Request.Url, Nothing))
            End If

    End Sub
End Class

The code uses a bit of reflection and I am sure can be helpful for figuring out the properties of any other object.

For this url:


The output is:

AbsolutePath: /tests/requesturl.aspx

AbsoluteUri: http://train.mindscapesolutions.com/tests/requesturl.aspx?query1=2&query2=3

Authority: train.mindscapesolutions.com

Host: train.mindscapesolutions.com

HostNameType: Dns

IsDefaultPort: True

IsFile: False

IsLoopback: False

IsUnc: False

LocalPath: /tests/requesturl.aspx

PathAndQuery: /tests/requesturl.aspx?query1=2&query2=3

Port: 80

Query: ?query1=2&query2=3


Scheme: http

OriginalString: http://train.mindscapesolutions.com:80/tests/requesturl.aspx?query1=2&query2=3

DnsSafeHost: train.mindscapesolutions.com

IsAbsoluteUri: True

Segments: System.String[]

UserEscaped: False


Aaron Brander is the VP of Technology for MINDSCAPE at Hanon McKendry.

Topics: Development, Marketing


Written by MINDSCAPE

We work with companies and organizations who want to get the most out of their digital marketing: more leads, more sales, more profit. Our success is measured by the hundreds of millions of dollars we help our clients generate each year.

Join the conversation

Subscribe to Email Updates

Let's Talk