[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

Logging page referrer from within Global.asax

I've got an extremely basic Global.asax file which records visitor information on each Session_Start event.  The file uses an insert statement to add a record to a database each time a new session is started.  My code for the insert statement is below.

strInsert                = "Insert Into TBL_SESSION_LOG ( SessionID, StartTime, EndTime, ElapsedTime, PageCount, State, Referer, InitialRemoteHost, InitialRemoteAddress, UserAgent )"

 strInsert                = strInsert & " Values ( '" & Session.SessionID & "', #" & Now() & "#, #" & Now() & "#, 0, 0, True, '" & Request.ServerVariables("http_referrer") & "', '" & Request( "REMOTE_HOST" ) & "', '" & Request( "REMOTE_ADDR" ) & "', 'fred' )"

The values it returns all seem okay except for the final two.
Referer ---> Request.ServerVariable("http_referrer")
UserAgent ---> 'fred'

(The second one is a pretty obvious error!)

Although this code does not generate any errors when run, it does not seem to be recording any values for Referer. HOW CAN I MODIFY MY CODE TO ENSURE 'REFERRER' AND 'USERAGENT' VALUES ARE RECORDED?  I believe I read somewhere that these values are generated per page returned from the site- not sure if Global.asax is a special exception which needs handling differently.
0
Beamson
Asked:
Beamson
1 Solution
 
clockwatcherCommented:

UserAgent should be in Request.ServerVariables("HTTP_USER_AGENT") and referrer should be in Request.ServerVariables("HTTP_REFERER") -- notice the spelling on it one 'R'.

Neither though are guaranteed to be present.  And, REFERER will typically only be present if it was from a link of another page.
0
 
BeamsonAuthor Commented:
The suggestions work. (I hadn't bothered trying the HTTP_USER_AGENT one because my HTTP_REFERRRRRRER one hadn't been working)  I had the right idea - just bad spelling!

Thanks for spotting it clockwatcher!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now