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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.