Getting HTTP_REFERER value

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I am trying to save the value of HTTP_REFERER so I can use it later on in
the webform as below;

Public Return_Address as string

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Return_Address = Request.ServerVariables("HTTP_REFERER")
End Sub

The problem is that Return_Address value always comes out blank. What am I
doing wrong?

Thanks

Regards
 
Hi John,

It will be empty the first time you open the page because there is no
referrer. After clicking the hyperlink in the code below, you should see the
value. Let us know how you make out?

<%@ Page Language="VB" %>
<script runat="server">

' Insert page code here
'
Public Return_Address as string

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Return_Address = Request.ServerVariables("HTTP_REFERER")
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:HyperLink id="HyperLink1" runat="server"
NavigateUrl="referrer.aspx">HyperLink</asp:HyperLink>
<%= Return_Address%>
</form>
</body>
</html>
 
In general, keep in mind the http version that is making the request. Http
1.0 and http 1.1 requests will yield different results for certain server
variables.
 
Back
Top