asp.netcontainsrequest.servervariables

comparing http_referer against http_host


Hi I need to check whether the http_referer is the same site as the current site.

I have the following code

Dim strReferer As String

strReferer = Request.ServerVariables("HTTP_REFERER")
If strReferer.Contains(Request.ServerVariables("HTTP_HOST")) then
   'do task
End If

This is throwing up an error saying - "Object reference not set to an instance of an object." and flagging the if line as the offending line of code.

Any ideas where I'm going wrong?

MY SOLUTION:

strReferer = "" & Request.ServerVariables("HTTP_REFERER")

Means the string always has a value even if it's nothing.


Solution

  • Because HTTP_REFERER is not always populated - only if you have clicked a link. So if you browse directly to a page, that header will be empty.