473,378 Members | 1,495 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,378 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 direcly 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 17 '05 #1
1 8042
Have you debugged the page to find out which line it is occuring on?
Are you sure this is the line?

If this line is the cause, it is possible that the referrer header was
not sent, in which case, calling that would return null, and then the call
to ToString would throw this exception.

You are better off doing this:

// No need to cast to a string, since it is a NameValueCollection, which
returns strings.
private string pagina =
System.Web.HttpContext.Current.Request.ServerVaria bles["HTTP_REFERER"];

// Check if null, if not, then continue.
if (pagina != null)
{
// Set the page.
pagina = System.IO.Path.GetFileName(pagina);

// Do the rest of the processing here.
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paperback Writer" <ne*********@gmail.com> wrote in message
news:uu**************@TK2MSFTNGP10.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 direcly 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 17 '05 #2

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. ...
9
by: Robert Mark Bram | last post by:
Hi All! I have the following in an ASP script: var bounceBackPage = Request.ServerVariables("HTTP_REFERER"); Response.Write("<p>bounceBackPage: " + bounceBackPage + ". Undefined? " +...
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...
5
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...
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.