473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problems with HTTP_REFERER

Hi, I have the following code in my ASPX:
private string pagina =
System.IO.Path.GetFileName(System.Web.HttpContext. Current.Request.ServerVariables["HTTP_REFERER"].ToUpper());

The problem is it: When i call this page directly i get an error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

I really need that, but i do not know how to accomplish this. Does someone
can help me ?
Nov 19 '05 #1
5 2015
If there is no HTTP_REFERER (no page from which this page was navigated to),
the ServerVariable will be null. You need to check for this, as "ToUpper()"
will throw an exception if the string is null.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven

"Paperback Writer" <ne*********@gmail.com> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
Hi, I have the following code in my ASPX:
private string pagina =
System.IO.Path.GetFileName(System.Web.HttpContext. Current.Request.ServerVariables["HTTP_REFERER"].ToUpper());

The problem is it: When i call this page directly i get an error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

I really need that, but i do not know how to accomplish this. Does someone
can help me ?

Nov 19 '05 #2
All it's saying is that there is no value for the HTTP_Referer item, that
means that the array item will be a null value. It's throwing an error
because you cannot convert a null value into an uppercase string, or any
string for that matter.

You have to first check and see if it's null before you attempt to access it

if(Request.ServerVariables["HTTP_REFERER"] != null)
{
// then you can do something
}

If you have to count on the referer information don't, you don't always
receive information so a lot of the times you'll simply have a null value
here.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
"Paperback Writer" <ne*********@gmail.com> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
Hi, I have the following code in my ASPX:
private string pagina =
System.IO.Path.GetFileName(System.Web.HttpContext. Current.Request.ServerVariables["HTTP_REFERER"].ToUpper());

The problem is it: When i call this page directly i get an error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

I really need that, but i do not know how to accomplish this. Does someone
can help me ?

Nov 19 '05 #3
your referer is probably an empty string if your not referred to the page
from somewhere- your trying to getfilename on an empty string hence the
exception, use a try catch or check the value of referrer first

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Paperback Writer" <ne*********@gmail.com> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
Hi, I have the following code in my ASPX:
private string pagina =
System.IO.Path.GetFileName(System.Web.HttpContext. Current.Request.ServerVariables["HTTP_REFERER"].ToUpper());

The problem is it: When i call this page directly i get an error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

I really need that, but i do not know how to accomplish this. Does someone
can help me ?

Nov 19 '05 #4
I can not check with clause IF because it's out of a method...it's a private
string into the class!

"John Timney (ASP.NET MVP)" <ti*****@despammed.com> escreveu na mensagem
news:e$**************@tk2msftngp13.phx.gbl...
your referer is probably an empty string if your not referred to the page
from somewhere- your trying to getfilename on an empty string hence the
exception, use a try catch or check the value of referrer first

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Paperback Writer" <ne*********@gmail.com> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
Hi, I have the following code in my ASPX:
private string pagina =
System.IO.Path.GetFileName(System.Web.HttpContext. Current.Request.ServerVariables["HTTP_REFERER"].ToUpper());

The problem is it: When i call this page directly i get an error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

I really need that, but i do not know how to accomplish this. Does
someone can help me ?


Nov 19 '05 #5
The fact that you can do this:

System.Web.HttpContext.Current.Request.ServerVaria bles["HTTP_REFERER"].ToUpp
er());

says you DO have access to the null string in question.

Richard

"Paperback Writer" <ne*********@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I can not check with clause IF because it's out of a method...it's a private string into the class!

"John Timney (ASP.NET MVP)" <ti*****@despammed.com> escreveu na mensagem
news:e$**************@tk2msftngp13.phx.gbl...
your referer is probably an empty string if your not referred to the page from somewhere- your trying to getfilename on an empty string hence the
exception, use a try catch or check the value of referrer first

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Paperback Writer" <ne*********@gmail.com> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
Hi, I have the following code in my ASPX:
private string pagina =
System.IO.Path.GetFileName(System.Web.HttpContext. Current.Request.ServerVari
ables["HTTP_REFERER"].ToUpper());
The problem is it: When i call this page directly i get an error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

I really need that, but i do not know how to accomplish this. Does
someone can help me ?



Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John A. Irwin | last post by:
I'm very new to PHP and am trying to figure out how to parse out a variable "HTTP_REFERER". My reason for this is my site was recently "FEATURED" (sic) on a website called FARK.COM. Because of...
2
by: Alex | last post by:
Hello, I am having trouble extracting the original referer in my 404 error script. This is what I have so far: 1) I set the .htaccess file to the following and it works fine: ErrorDocument...
9
by: deko | last post by:
I have a page that I don't want anyone to be able to link directly to. The page should only be accessed from gatepage.php. I tried this code, but keep getting errors - "header info already sent",...
2
by: ssk | last post by:
Hello! I made a web site using PHP Open sources for message board. Everything's fine except one computer can't open a message writing page. The code that gives an error is the following. ...
2
by: M Smith | last post by:
On our web site we allow our members access to features hosted by another web site. The way the other web site authenticates users is to check the value of the HTTP_REFERER. If it comes from our...
4
by: Ringo Langly | last post by:
Hi everyone, We're using an outside vendor to provide some content for our website, and they use the http_referer variable to verify their content is only viewed from subscribing customers. ...
28
by: Prabhat | last post by:
Hello, I have the below requirement. When ever my website is opened by any link: say clicked from the google search result or a link from other website: Then I should able to know the...
1
by: Paperback Writer | last post by:
Hi, I have the following code in my ASPX: private string pagina = System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.ServerVariables.ToUpper()); The problem is it: When i call this...
8
by: tshad | last post by:
Why would HTTP_REFERER not be there in the Page_Load event? I am using it to determine whether a page was called from a particular page. I am doing: sTest =...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.