Name

UrlReferrer

Synopsis

uriObj = Request.UrlReferrer

Returns an instance of the Uri class containing properties that describe the URL for the resource from which the user navigated to the current requested resource. If the user did not navigate to the current resource (i.e., if the current resource is accessed directly), the UrlReferrer property returns Nothing.

Parameters

uriObj

An Object variable of type Uri.

Example

The example uses the Uri object that the UrlReferrer property returned in order to write information about the URL for the referring resource to the browser:

Sub Page_Load(  )
   Dim myUri As Uri
   myUri = Request.UrlReferrer
  
   If Not (myUri Is Nothing) Then
      Message.Text = "Referral URL info - <br/><br/>"
      Message.Text &= "Protocol: " & myUri.Scheme & "<br/>"
      Message.Text &= "Port: " & myUri.Port & "<br/>"
      Message.Text &= "Host Name: " & myUri.Host & "<br/>"
      Message.Text &= "App Path: " & myUri.AbsolutePath & "<br/>"
   Else
      Message.Text = "No referral URL info available."
   End If
End Sub

The following code can link to the example page:

<html>
   <head>
      <title>Link to UrlReferrer</title>
   </head>
<body>
   <a href="UrlReferrer.aspx">Go to UrlReferrer.aspx</a>
</body>
</html>

Notes

The example code makes sure that the UrlReferrer property returns a valid instance of the Uri class. The UrlReferrer property returns Nothing if the page is accessed directly, rather than from a link on another page.

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.