User's Browser Not Seing Server Variables

G

George Durzi

I'm encountering an odd problem with one of my users accessing my web
application.

The first line in the Page_Load function of this webform is:
string sReferer = Request.ServerVariables["HTTP_REFERER"].ToString()

When the user accesses this page, the code immediately breaks at this line,
giving him the standard:
Object reference not set to an instance of an object.

I logged in as him locally and verified in my trace that I could see the
server variable. Also, it's not possible for him in the application to get
to that page before logging in, so there should always be a value for the
referer.

So anyway, I commented out that line, and it all works fine for him.


Is there anything that could prevent a user from "seeing" the Server
Variables collection? Could it be a security setting on their PC?


The user is running:
Windows XP SP2
Privacy Settings set to Medium
Active Scripting enabled


Thanks!
 
J

Jim Cheshire [MSFT]

Hi George,

The user is not actually seeing the server variable. That variable is
being returned directly to your code via IIS. The problem is almost
certainly being caused by the state of the Request object at the time he is
hitting the page.

I think the best thing for you to do here would be to turn on all options
in IIS logging and check the log when he sees this. IIS will log the
referrer.

Jim Cheshire [MSFT]
MCP+I, MCSE, MCSD, MCDBA
ASP.NET Developer Support
(e-mail address removed)

This post is provided "AS-IS" with no warranties and confers no rights.


--------------------
| From: "George Durzi" <[email protected]>
| Subject: User's Browser Not Seing Server Variables
| Date: Wed, 10 Nov 2004 07:52:07 -0700
| Lines: 31
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip68-2-106-229.ph.ph.cox.net 68.2.106.229
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14
phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.aspnet:275010
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I'm encountering an odd problem with one of my users accessing my web
| application.
|
| The first line in the Page_Load function of this webform is:
| string sReferer = Request.ServerVariables["HTTP_REFERER"].ToString()
|
| When the user accesses this page, the code immediately breaks at this
line,
| giving him the standard:
| Object reference not set to an instance of an object.
|
| I logged in as him locally and verified in my trace that I could see the
| server variable. Also, it's not possible for him in the application to
get
| to that page before logging in, so there should always be a value for the
| referer.
|
| So anyway, I commented out that line, and it all works fine for him.
|
|
| Is there anything that could prevent a user from "seeing" the Server
| Variables collection? Could it be a security setting on their PC?
|
|
| The user is running:
| Windows XP SP2
| Privacy Settings set to Medium
| Active Scripting enabled
|
|
| Thanks!
|
|
|
 
A

Ariel Popovsky

Hello George,

This is what I think is happening, the user's browser is blocking the referer so Request.ServerVariables["HTTP_REFERER"] returns null and when you call ToString() on null the NullReferenceException raises. Since the property ServerVariables is a NameValueCollection, you don´t need to call ToString(), try this instead: sReferer = Request.ServerVariables["HTTP_REFERER"].

Greetings,
 
G

George Durzi

Thank you! I'll try that.

This way I can deal with it in my code if its value is null or string.empty

George

Ariel Popovsky said:
Hello George,

This is what I think is happening, the user's browser is blocking the
referer so Request.ServerVariables["HTTP_REFERER"] returns null and when
you call ToString() on null the NullReferenceException raises. Since the
property ServerVariables is a NameValueCollection, you don´t need to call
ToString(), try this instead: sReferer =
Request.ServerVariables["HTTP_REFERER"].

Greetings,
-----
Ariel Popovsky

I'm encountering an odd problem with one of my users accessing my web
application.

The first line in the Page_Load function of this webform is: string
sReferer = Request.ServerVariables["HTTP_REFERER"].ToString()

When the user accesses this page, the code immediately breaks at this
line,
giving him the standard:
Object reference not set to an instance of an object.
I logged in as him locally and verified in my trace that I could see
the server variable. Also, it's not possible for him in the
application to get to that page before logging in, so there should
always be a value for the referer.

So anyway, I commented out that line, and it all works fine for him.

Is there anything that could prevent a user from "seeing" the Server
Variables collection? Could it be a security setting on their PC?

The user is running:
Windows XP SP2
Privacy Settings set to Medium
Active Scripting enabled
Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,219
Latest member
KristieKoh

Latest Threads

Top