473,698 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTTP_REFERER not always there

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 = Request.ServerV ariables("HTTP_ REFERER")
if (sTest = "") ORELSE (sTest.SubStrin g(sTest.LastInd exOf("/")+1) <>
"job_posting_ne w2.aspx") then
newPosition = new Position
session.Remove( "newPositio n")
else
newPosition = session("newPos ition")
end if

I was originally doing:

if (sTest.SubStrin g(sTest.LastInd exOf("/")+1)

But if HTTP_REFERER wasn't there, I would get an error:

Object reference not set to an instance of an object.

Not sure why.

Thanks,

Tom
Nov 19 '05 #1
8 1855
Are you using Request.Redirec t or Server.Transfer in the previous page?
Don't think you will be getting a HTTP_REFERER value then, only if you came
to the page as a result of clicking on a link.

Shawn
"tshad" <tf*@dslextreme .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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 = Request.ServerV ariables("HTTP_ REFERER")
if (sTest = "") ORELSE (sTest.SubStrin g(sTest.LastInd exOf("/")+1) <>
"job_posting_ne w2.aspx") then
newPosition = new Position
session.Remove( "newPositio n")
else
newPosition = session("newPos ition")
end if

I was originally doing:

if (sTest.SubStrin g(sTest.LastInd exOf("/")+1)

But if HTTP_REFERER wasn't there, I would get an error:

Object reference not set to an instance of an object.

Not sure why.

Thanks,

Tom

Nov 19 '05 #2
Hi Tshad,

I think you should check the null reference before referencing it. You
should not depends on this variable. The variable is sent by the browser, it
is not a must there is always one as there is a number of browser out there
(IE, Firefox, etc). Also, some security software may block the HTTP_REFERER.

Regards,
Jack Li
MVP (ASP.NET)

"tshad" <tf*@dslextreme .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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 = Request.ServerV ariables("HTTP_ REFERER")
if (sTest = "") ORELSE (sTest.SubStrin g(sTest.LastInd exOf("/")+1) <>
"job_posting_ne w2.aspx") then
newPosition = new Position
session.Remove( "newPositio n")
else
newPosition = session("newPos ition")
end if

I was originally doing:

if (sTest.SubStrin g(sTest.LastInd exOf("/")+1)

But if HTTP_REFERER wasn't there, I would get an error:

Object reference not set to an instance of an object.

Not sure why.

Thanks,

Tom

Nov 19 '05 #3
This could be not available (this is optional and some browser my block this
for privacy purpose) plus it won't be there if the the user have the page in
its favorites...

You could keep track of the previous page in the session variable as you
seems to do...

--
Patrice

"tshad" <tf*@dslextreme .com> a écrit dans le message de
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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 = Request.ServerV ariables("HTTP_ REFERER")
if (sTest = "") ORELSE (sTest.SubStrin g(sTest.LastInd exOf("/")+1) <>
"job_posting_ne w2.aspx") then
newPosition = new Position
session.Remove( "newPositio n")
else
newPosition = session("newPos ition")
end if

I was originally doing:

if (sTest.SubStrin g(sTest.LastInd exOf("/")+1)

But if HTTP_REFERER wasn't there, I would get an error:

Object reference not set to an instance of an object.

Not sure why.

Thanks,

Tom

Nov 19 '05 #4
Hi, tshad.

re:
I was originally doing:
if (sTest.SubStrin g(sTest.LastInd exOf("/")+1)
But if HTTP_REFERER wasn't there, I would get an error:
Object reference not set to an instance of an object.
Not sure why.
Because there's no LastIndexOf a null object.

If the page hasn't been referred from another page, HTTP_REFERER is null.


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
=============== =============== ========
"tshad" <tf*@dslextreme .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. .. 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 = Request.ServerV ariables("HTTP_ REFERER")
if (sTest = "") ORELSE (sTest.SubStrin g(sTest.LastInd exOf("/")+1) <>
"job_posting_ne w2.aspx") then
newPosition = new Position
session.Remove( "newPositio n")
else
newPosition = session("newPos ition")
end if

I was originally doing:

if (sTest.SubStrin g(sTest.LastInd exOf("/")+1)

But if HTTP_REFERER wasn't there, I would get an error:

Object reference not set to an instance of an object.

Not sure why.

Thanks,

Tom

Nov 19 '05 #5
"Patrice" <no****@nowhere .com> wrote in message
news:Ob******** ******@tk2msftn gp13.phx.gbl...
This could be not available (this is optional and some browser my block
this
for privacy purpose) plus it won't be there if the the user have the page
in
its favorites...

You could keep track of the previous page in the session variable as you
seems to do...
But the problem with that is I would need to put that in all my pages.

Mainly, I have a few pages that are connected, such as an Application may
take 5 pages to finish and I want to make sure that the use doesn't go
directly to page 3 from a Browser entry. I want them to go to Page 1 first
and push the next button (or previous button after the first page) to
navigate the pages. To do this I need to know that page 3 got there from
either page 2 or page 4. The referer would be the logical place to look,
but if some browsers are preventing that, then I can't very well use that.

It really makes that ServerVariable virtually useless. If you can't depend
on it, how can you use it.

Tom
--
Patrice

"tshad" <tf*@dslextreme .com> a écrit dans le message de
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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 = Request.ServerV ariables("HTTP_ REFERER")
if (sTest = "") ORELSE (sTest.SubStrin g(sTest.LastInd exOf("/")+1)
<>
"job_posting_ne w2.aspx") then
newPosition = new Position
session.Remove( "newPositio n")
else
newPosition = session("newPos ition")
end if

I was originally doing:

if (sTest.SubStrin g(sTest.LastInd exOf("/")+1)

But if HTTP_REFERER wasn't there, I would get an error:

Object reference not set to an instance of an object.

Not sure why.

Thanks,

Tom


Nov 19 '05 #6
ServerVariables only reflect what browser has sent to the server (plus some server info).

If browser sent the HTTP_REFERER then ServerVariable will have that info, if it did not send that then nobody in a world will get it.

On real life server (on interent) the HTPP_REFERER is missing from 30% of all requests. So you will have to simply deal with that fact.


George.

"tshad" <ts**********@f tsolutions.com> wrote in message news:uN******** ******@TK2MSFTN GP12.phx.gbl...
"Patrice" <no****@nowhere .com> wrote in message
news:Ob******** ******@tk2msftn gp13.phx.gbl...
This could be not available (this is optional and some browser my block
this
for privacy purpose) plus it won't be there if the the user have the page
in
its favorites...

You could keep track of the previous page in the session variable as you
seems to do...
But the problem with that is I would need to put that in all my pages.

Mainly, I have a few pages that are connected, such as an Application may
take 5 pages to finish and I want to make sure that the use doesn't go
directly to page 3 from a Browser entry. I want them to go to Page 1 first
and push the next button (or previous button after the first page) to
navigate the pages. To do this I need to know that page 3 got there from
either page 2 or page 4. The referer would be the logical place to look,
but if some browsers are preventing that, then I can't very well use that.

It really makes that ServerVariable virtually useless. If you can't depend
on it, how can you use it.

Tom
--
Patrice

"tshad" <tf*@dslextreme .com> a écrit dans le message de
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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 = Request.ServerV ariables("HTTP_ REFERER")
if (sTest = "") ORELSE (sTest.SubStrin g(sTest.LastInd exOf("/")+1)
<>
"job_posting_ne w2.aspx") then
newPosition = new Position
session.Remove( "newPositio n")
else
newPosition = session("newPos ition")
end if

I was originally doing:

if (sTest.SubStrin g(sTest.LastInd exOf("/")+1)

But if HTTP_REFERER wasn't there, I would get an error:

Object reference not set to an instance of an object.

Not sure why.

Thanks,

Tom



Nov 19 '05 #7
If you have only 5 pages where you need to keep track of that it looks like
not that cumbersome. Another option is to put this in some general place
that is always executed (perhaps beginrequest if you don't have such a
general place for now).

--
Patrice

"tshad" <ts**********@f tsolutions.com> a écrit dans le message de
news:uN******** ******@TK2MSFTN GP12.phx.gbl...
"Patrice" <no****@nowhere .com> wrote in message
news:Ob******** ******@tk2msftn gp13.phx.gbl...
This could be not available (this is optional and some browser my block
this
for privacy purpose) plus it won't be there if the the user have the page in
its favorites...

You could keep track of the previous page in the session variable as you
seems to do...
But the problem with that is I would need to put that in all my pages.

Mainly, I have a few pages that are connected, such as an Application may
take 5 pages to finish and I want to make sure that the use doesn't go
directly to page 3 from a Browser entry. I want them to go to Page 1

first and push the next button (or previous button after the first page) to
navigate the pages. To do this I need to know that page 3 got there from
either page 2 or page 4. The referer would be the logical place to look,
but if some browsers are preventing that, then I can't very well use that.

It really makes that ServerVariable virtually useless. If you can't depend on it, how can you use it.

Tom

--
Patrice

"tshad" <tf*@dslextreme .com> a écrit dans le message de
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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 = Request.ServerV ariables("HTTP_ REFERER")
if (sTest = "") ORELSE (sTest.SubStrin g(sTest.LastInd exOf("/")+1)
<>
"job_posting_ne w2.aspx") then
newPosition = new Position
session.Remove( "newPositio n")
else
newPosition = session("newPos ition")
end if

I was originally doing:

if (sTest.SubStrin g(sTest.LastInd exOf("/")+1)

But if HTTP_REFERER wasn't there, I would get an error:

Object reference not set to an instance of an object.

Not sure why.

Thanks,

Tom



Nov 19 '05 #8
"Patrice" <no****@nowhere .com> wrote in message
news:Oa******** ******@TK2MSFTN GP15.phx.gbl...
If you have only 5 pages where you need to keep track of that it looks
like
not that cumbersome. Another option is to put this in some general place
that is always executed (perhaps beginrequest if you don't have such a
general place for now).
It is not really a cumbersome problem, but a problem with making sure that
page 2 is only loaded after page 1 or 3, 3 is only loaded after 2 or 4, etc.

I also need to make sure that page one, when not entered from page 2 reads
my data from Sql and my old session variables, if they exist, are cleared..
If it comes from page 2 then get the data from my session variables.

This would have been perfect with the referer.

I am going to have to put in all of my pages on entry, an entry in my
session variables that says what this page is. That way the next page I go
to will know what the previous page was.

I would have assumed that if I did a redirect, I would be able to tell where
the page came from.

Apparently, that is not the case.

Thanks,

Tom
--
Patrice

"tshad" <ts**********@f tsolutions.com> a écrit dans le message de
news:uN******** ******@TK2MSFTN GP12.phx.gbl...
"Patrice" <no****@nowhere .com> wrote in message
news:Ob******** ******@tk2msftn gp13.phx.gbl...
> This could be not available (this is optional and some browser my block
> this
> for privacy purpose) plus it won't be there if the the user have the page > in
> its favorites...
>
> You could keep track of the previous page in the session variable as
> you
> seems to do...


But the problem with that is I would need to put that in all my pages.

Mainly, I have a few pages that are connected, such as an Application may
take 5 pages to finish and I want to make sure that the use doesn't go
directly to page 3 from a Browser entry. I want them to go to Page 1

first
and push the next button (or previous button after the first page) to
navigate the pages. To do this I need to know that page 3 got there from
either page 2 or page 4. The referer would be the logical place to look,
but if some browsers are preventing that, then I can't very well use
that.

It really makes that ServerVariable virtually useless. If you can't

depend
on it, how can you use it.

Tom
>
> --
> Patrice
>
> "tshad" <tf*@dslextreme .com> a écrit dans le message de
> news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
>> 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 = Request.ServerV ariables("HTTP_ REFERER")
>> if (sTest = "") ORELSE
>> (sTest.SubStrin g(sTest.LastInd exOf("/")+1)
>> <>
>> "job_posting_ne w2.aspx") then
>> newPosition = new Position
>> session.Remove( "newPositio n")
>> else
>> newPosition = session("newPos ition")
>> end if
>>
>> I was originally doing:
>>
>> if (sTest.SubStrin g(sTest.LastInd exOf("/")+1)
>>
>> But if HTTP_REFERER wasn't there, I would get an error:
>>
>> Object reference not set to an instance of an object.
>>
>> Not sure why.
>>
>> Thanks,
>>
>> Tom
>>
>>
>
>



Nov 19 '05 #9

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

Similar topics

2
5634
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. if(!eregi($HTTP_HOST,$HTTP_REFERER)) Error("Write in the normal way");
2
1602
by: klynn | last post by:
I'm writing an application where I need to know the URL of the user that entered my application (the user comes in from a completely different site who knows where and who knows how). For all I know, the user wrote an HTML page with a button that does window.open("http://mywebpage/myloginpage.aspx"). So in myloginpage.aspx, I check for the following: Dim strWhere As String = Request.ServerVariables("HTTP_REFERER") But its always...
2
1666
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 Login.asp page it lets them in. When our users login to go to the other site, they login on our site's Login.asp page. When they click submit, our LoginCheck.asp page validates them and does a response.redirect to the other site. In most cases...
9
2974
by: Nicolae Fieraru | last post by:
Hi All, I try to use Request.ServerVariables("HTTP_REFERER") in a script and I discovered it doesn't work as expected. I use XP with SP2 and I created a link on a web site which points to an asp page which should show the referer. I placed a link on www.eleader.com.au/linkref.html and there is a link pointing to www.monitortest.net/referer.asp When I use my computer with XP SP2, and I click on the first link, I get no referer. But when...
4
5286
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. Anyway, we're using the mm_menu javascript menu for our web menus, and under only Internet Explorer it's not passing the http_referer -- which means any site of theirs we link to from the menu doesn't work. This works fine in Firefox, Mozilla, and...
28
4880
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 referrer URL. How Do I get that? I know about Request.ServerVariables("HTTP_REFERER"). So I used this in
2
1986
by: John | last post by:
Hi I am trying to save the value of HTTP_REFERER so I can use it later on in the webform as below; Public Return_Address as string Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Return_Address = Request.ServerVariables("HTTP_REFERER")
15
15432
by: Drebin | last post by:
I am retrofitting a central login application and want to be able to read the Request.ServerVariables so that when they have logged on, I can send them back to wherever they were trying to go.. If you try to load a legacy ASP app, I do this: If Len(SessionID) <> 40 Then Response.Redirect "/WAS/Default.aspx?AppCode=2400" End If
5
2036
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 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
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7728
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.