Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

HTTP_REFERER is null on global.asax's Application_Error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Seguros Catatumbo - 13 Sep 2007 16:28 GMT
Hi everyone. Is there a way i can find out the value of HTTP_REFERER
when using application_error in global.asax?

I am using:

if (HttpContext.Current.Request.ServerVariables["HTTP_REFERER"] !=
null)
{
    referencia =
HttpContext.Current.Request.ServerVariables["HTTP_REFERER"].ToString();
}

and it still is null
bruce barker - 13 Sep 2007 16:41 GMT
it is optional for the browser to send this value.

-- bruce (sqlwork.com)

> Hi everyone. Is there a way i can find out the value of HTTP_REFERER
> when using application_error in global.asax?
[quoted text clipped - 9 lines]
>
> and it still is null
ThatsIT.net.au - 13 Sep 2007 16:49 GMT
try detecting the referrer in the session on start sub, then store it in a
session variable. you can then call it from the application error sub.

I think it worth a try

> Hi everyone. Is there a way i can find out the value of HTTP_REFERER
> when using application_error in global.asax?
[quoted text clipped - 9 lines]
>
> and it still is null
Mark Rae [MVP] - 13 Sep 2007 17:12 GMT
> Is there a way i can find out the value of HTTP_REFERER

Not 100% reliably - some browsers deliberately do not send this, and some
ISPs deliberately strip it from headers...

What are you trying to achieve...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Juan T. Llibre - 13 Sep 2007 17:21 GMT
re:
!> Not 100% reliably - some browsers deliberately do not send this,
!> and some ISPs deliberately strip it from headers...

Plus, some users don't come from a referring page...

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/
======================================

>> Is there a way i can find out the value of HTTP_REFERER
>
> Not 100% reliably - some browsers deliberately do not send this, and some ISPs deliberately strip it from headers...
>
> What are you trying to achieve...?
Mark Rae [MVP] - 13 Sep 2007 18:23 GMT
> re:
> !> Not 100% reliably - some browsers deliberately do not send this,
> !> and some ISPs deliberately strip it from headers...
>
> Plus, some users don't come from a referring page...

Indeed.

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

FJ - 13 Sep 2007 18:15 GMT
> Not 100% reliably - some browsers deliberately do not send this, and some
> ISPs deliberately strip it from headers...
>
> What are you trying to achieve...?

I am making a custom error page, and for debugging purposes i want to
send through email which page the user came from, if i can, to make
debugging easier (with debugging OFF)

On classic asp, i had a custom error page, which emailed me even the
file name of the page that had the problem, and the line in most
cases. I can't seem to do this on asp.net unless i turn on debugging,
which causes performance degradation.
Mark Rae [MVP] - 13 Sep 2007 18:28 GMT
>> Not 100% reliably - some browsers deliberately do not send this, and some
>> ISPs deliberately strip it from headers...
[quoted text clipped - 9 lines]
> cases. I can't seem to do this on asp.net unless i turn on debugging,
> which causes performance degradation.

But that's not the same thing... The "file name of the page that had the
problem" is readily accessible within the Exception object...

What you're asking for (or, at least, what you appear to be asking for) is
the name of the page which sent the user to the page that had the problem...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Seguros Catatumbo - 13 Sep 2007 18:44 GMT
> But that's not the same thing... The "file name of the page that had the
> problem" is readily accessible within the Exception object...
>
> What you're asking for (or, at least, what you appear to be asking for) is
> the name of the page which sent the user to the page that had the problem...

Of course it isn't the same thing, that's a separate issue i am
having.

What i want is to redirect the user to a pretty custom error page
which on the backend emails me the url that the user was on when he
got the error, the file name of the code where the error happened, the
line it ocurred on, etc, but while having debugging off. In classic
asp this is very easy to do:

set objError = Server.getLastError()
numero = objError.AspCode
pagina = objError.File
descripcion = objError.Description
fuente = Server.HTMLEncode(objError.Source)
linea = ObjError.Line
iis = ObjError.ASPDescription

Put that in an email and that's it.
Patrice - 13 Sep 2007 18:33 GMT
So it will be there or not. My personal strategy is to dump all server
variables possibly opting out those I'm not interested in (for example you
can see those added by a proxy and that you wouldn't have been able to
explictely queryetc...)

Classic ASP is not compiled and so providing the line number was much more
easy. I made a quick search once but IMO this is not something that is
really compilcated to overcome. Bascially a good principle is to have short
procedures (and you have the call stack) and once you know what the error
message means is it's quite easy to find out which line could have produced
the error.

--
Patrice

>> Not 100% reliably - some browsers deliberately do not send this, and some
>> ISPs deliberately strip it from headers...
[quoted text clipped - 9 lines]
> cases. I can't seem to do this on asp.net unless i turn on debugging,
> which causes performance degradation.
Patrice - 13 Sep 2007 17:13 GMT
Try ALL_HTTP and see if it's available :
- depends from where the user come
- also this is not required so a browser (or its user) could choose not to
provide this information

--
Patrice

> Hi everyone. Is there a way i can find out the value of HTTP_REFERER
> when using application_error in global.asax?
[quoted text clipped - 9 lines]
>
> and it still is null
Peter Bromberg [C# MVP] - 13 Sep 2007 18:42 GMT
1) Referer is only sent when the page arrived on is through a user clicking a
link.
2) the exception you capture in Application_Error contains lots of
properties including a StackTrace property that outlines the entire stack
walk of the exception including where and in what method and on what line
number it originated.
-- Peter
Recursion: see Recursion
site:  http://www.eggheadcafe.com
unBlog:  http://petesbloggerama.blogspot.com
BlogMetaFinder:    http://www.blogmetafinder.com

> Hi everyone. Is there a way i can find out the value of HTTP_REFERER
> when using application_error in global.asax?
[quoted text clipped - 9 lines]
>
> and it still is null
Seguros Catatumbo - 13 Sep 2007 19:40 GMT
> 2) the exception you capture in Application_Error contains lots of
> properties including a StackTrace property that outlines the entire stack
> walk of the exception including where and in what method and on what line
> number it originated.

That is only true if you have debugging on, which is kind of what i
want to avoid.

If i turn debugging off, this is the stack trace i get when i simply
assign a null request variable to a string:

at _Default.Page_Load(Object sender, EventArgs e) at
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object
o, Object
t, EventArgs e) at
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs
e) at System.Web.UI.Control.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint)

which doesn't help me at all. At least i would need the function name
to have an idea of where it failed
Peter Bromberg [C# MVP] - 13 Sep 2007 20:02 GMT
if you deploy the PDB file in your release build, all the same stacktrace
information that you see in debug mode will be captured in release mode. I've
been doing this for years to log exception information to a database in real
time release - deployed ASP.NET apps.
-- Peter
Recursion: see Recursion
site:  http://www.eggheadcafe.com
unBlog:  http://petesbloggerama.blogspot.com
BlogMetaFinder:    http://www.blogmetafinder.com

> > 2) the exception you capture in Application_Error contains lots of
> > properties including a StackTrace property that outlines the entire stack
[quoted text clipped - 21 lines]
> which doesn't help me at all. At least i would need the function name
> to have an idea of where it failed
Seguros Catatumbo - 14 Sep 2007 03:09 GMT
> if you deploy the PDB file in your release build, all the same stacktrace
> information that you see in debug mode will be captured in release mode. I've
> been doing this for years to log exception information to a database in real
> time release - deployed ASP.NET apps.

Can you elaborate on this? I am using web developer express, and
looking through the web, i dont have an option in the property pages
to enable debug symbols. I am fairly new to asp.net, but i have seen
those .pdb files around. Do i have to copy it to the same directory as
web.config or something like that?
Mark Rae [MVP] - 14 Sep 2007 07:56 GMT
> Do i have to copy it to the same directory as web.config

It needs to go in the same folder as your app's DLL...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Juan T. Llibre - 14 Sep 2007 10:32 GMT
That will do it.

The only caveat is that the debugging has to be done locally, if using VWDE.
Remote debugging is not supported in VWDE; only in Visual Studio.

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/
======================================

>> Do i have to copy it to the same directory as web.config
>
> It needs to go in the same folder as your app's DLL...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.