Tags

, ,

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 &= String.Format("{0}: {1}<br><br>", a.Name, a.GetValue(Request.Url, Nothing))
            End If

        Next
    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:

http://train.mindscapesolutions.com/tests/requesturl.aspx?query1=test&query2=test

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
Fragment:
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
UserInfo:

Advertisements