By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,672 Members | 1,628 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,672 IT Pros & Developers. It's quick & easy.

HTTP_REFERER not always there

P: n/a
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.ServerVariables("HTTP_REFERER")
if (sTest = "") ORELSE (sTest.SubString(sTest.LastIndexOf("/")+1) <>
"job_posting_new2.aspx") then
newPosition = new Position
session.Remove("newPosition")
else
newPosition = session("newPosition")
end if

I was originally doing:

if (sTest.SubString(sTest.LastIndexOf("/")+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
Share this Question
Share on Google+
8 Replies


P: n/a
Are you using Request.Redirect 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****************@TK2MSFTNGP15.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.ServerVariables("HTTP_REFERER")
if (sTest = "") ORELSE (sTest.SubString(sTest.LastIndexOf("/")+1) <>
"job_posting_new2.aspx") then
newPosition = new Position
session.Remove("newPosition")
else
newPosition = session("newPosition")
end if

I was originally doing:

if (sTest.SubString(sTest.LastIndexOf("/")+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

P: n/a
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****************@TK2MSFTNGP15.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.ServerVariables("HTTP_REFERER")
if (sTest = "") ORELSE (sTest.SubString(sTest.LastIndexOf("/")+1) <>
"job_posting_new2.aspx") then
newPosition = new Position
session.Remove("newPosition")
else
newPosition = session("newPosition")
end if

I was originally doing:

if (sTest.SubString(sTest.LastIndexOf("/")+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

P: n/a
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****************@TK2MSFTNGP15.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.ServerVariables("HTTP_REFERER")
if (sTest = "") ORELSE (sTest.SubString(sTest.LastIndexOf("/")+1) <>
"job_posting_new2.aspx") then
newPosition = new Position
session.Remove("newPosition")
else
newPosition = session("newPosition")
end if

I was originally doing:

if (sTest.SubString(sTest.LastIndexOf("/")+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

P: n/a
Hi, tshad.

re:
I was originally doing:
if (sTest.SubString(sTest.LastIndexOf("/")+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****************@TK2MSFTNGP15.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.ServerVariables("HTTP_REFERER")
if (sTest = "") ORELSE (sTest.SubString(sTest.LastIndexOf("/")+1) <>
"job_posting_new2.aspx") then
newPosition = new Position
session.Remove("newPosition")
else
newPosition = session("newPosition")
end if

I was originally doing:

if (sTest.SubString(sTest.LastIndexOf("/")+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

P: n/a
"Patrice" <no****@nowhere.com> wrote in message
news:Ob**************@tk2msftngp13.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****************@TK2MSFTNGP15.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.ServerVariables("HTTP_REFERER")
if (sTest = "") ORELSE (sTest.SubString(sTest.LastIndexOf("/")+1)
<>
"job_posting_new2.aspx") then
newPosition = new Position
session.Remove("newPosition")
else
newPosition = session("newPosition")
end if

I was originally doing:

if (sTest.SubString(sTest.LastIndexOf("/")+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

P: n/a
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**********@ftsolutions.com> wrote in message news:uN**************@TK2MSFTNGP12.phx.gbl...
"Patrice" <no****@nowhere.com> wrote in message
news:Ob**************@tk2msftngp13.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****************@TK2MSFTNGP15.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.ServerVariables("HTTP_REFERER")
if (sTest = "") ORELSE (sTest.SubString(sTest.LastIndexOf("/")+1)
<>
"job_posting_new2.aspx") then
newPosition = new Position
session.Remove("newPosition")
else
newPosition = session("newPosition")
end if

I was originally doing:

if (sTest.SubString(sTest.LastIndexOf("/")+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

P: n/a
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**********@ftsolutions.com> a écrit dans le message de
news:uN**************@TK2MSFTNGP12.phx.gbl...
"Patrice" <no****@nowhere.com> wrote in message
news:Ob**************@tk2msftngp13.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****************@TK2MSFTNGP15.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.ServerVariables("HTTP_REFERER")
if (sTest = "") ORELSE (sTest.SubString(sTest.LastIndexOf("/")+1)
<>
"job_posting_new2.aspx") then
newPosition = new Position
session.Remove("newPosition")
else
newPosition = session("newPosition")
end if

I was originally doing:

if (sTest.SubString(sTest.LastIndexOf("/")+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

P: n/a
"Patrice" <no****@nowhere.com> wrote in message
news:Oa**************@TK2MSFTNGP15.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**********@ftsolutions.com> a écrit dans le message de
news:uN**************@TK2MSFTNGP12.phx.gbl...
"Patrice" <no****@nowhere.com> wrote in message
news:Ob**************@tk2msftngp13.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****************@TK2MSFTNGP15.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.ServerVariables("HTTP_REFERER")
>> if (sTest = "") ORELSE
>> (sTest.SubString(sTest.LastIndexOf("/")+1)
>> <>
>> "job_posting_new2.aspx") then
>> newPosition = new Position
>> session.Remove("newPosition")
>> else
>> newPosition = session("newPosition")
>> end if
>>
>> I was originally doing:
>>
>> if (sTest.SubString(sTest.LastIndexOf("/")+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 discussion thread is closed

Replies have been disabled for this discussion.