HTTP_REFERER is null on global.asax's Application_Error

  • Thread starter Thread starter Seguros Catatumbo
  • Start date Start date
S

Seguros Catatumbo

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
 
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
 
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...?
 
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
 
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/
======================================
 
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.
 
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.
 
FJ said:
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.


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...
 
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.
 
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
 
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.
 
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
 
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?
 
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/
======================================
 
Back
Top