HTTP_REFERER is null on global.asax's Application_Error

Discussion in 'ASP .Net' started by Seguros Catatumbo, Sep 13, 2007.

  1. 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
    Seguros Catatumbo, Sep 13, 2007
    #1
    1. Advertising

  2. Seguros Catatumbo

    bruce barker Guest

    it is optional for the browser to send this value.

    -- bruce (sqlwork.com)

    Seguros Catatumbo wrote:
    > 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, Sep 13, 2007
    #2
    1. Advertising

  3. 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


    "Seguros Catatumbo" <> wrote in message
    news:...
    > 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
    >
    ThatsIT.net.au, Sep 13, 2007
    #3
  4. "Seguros Catatumbo" <> wrote in message
    news:...

    > 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
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Sep 13, 2007
    #4
  5. Seguros Catatumbo

    Patrice Guest

    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

    "Seguros Catatumbo" <> a écrit dans le message de
    news: ...
    > 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
    >
    Patrice, Sep 13, 2007
    #5
  6. 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/
    ======================================
    "Mark Rae [MVP]" <> wrote in message news:...
    > "Seguros Catatumbo" <> wrote in message
    > news:...
    >
    >> 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
    > ASP.NET MVP
    > http://www.markrae.net
    Juan T. Llibre, Sep 13, 2007
    #6
  7. Seguros Catatumbo

    FJ Guest


    > 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.
    FJ, Sep 13, 2007
    #7
  8. "Juan T. Llibre" <> wrote in message
    news:...

    > 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.


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Sep 13, 2007
    #8
  9. "FJ" <> wrote in message
    news:...
    >
    >> 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.



    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...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Sep 13, 2007
    #9
  10. Seguros Catatumbo

    Patrice Guest

    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

    "FJ" <> a écrit dans le message de news:
    ...
    >
    >> 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.
    >
    >
    Patrice, Sep 13, 2007
    #10
  11. 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



    "Seguros Catatumbo" wrote:

    > 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
    >
    >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Sep 13, 2007
    #11

  12. > 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.
    Seguros Catatumbo, Sep 13, 2007
    #12

  13. > 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
    Seguros Catatumbo, Sep 13, 2007
    #13
  14. 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



    "Seguros Catatumbo" wrote:

    >
    > > 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
    >
    >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Sep 13, 2007
    #14
  15. > 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?
    Seguros Catatumbo, Sep 14, 2007
    #15
  16. "Seguros Catatumbo" <> wrote in message
    news:...

    > 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...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Sep 14, 2007
    #16
  17. 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/
    ======================================
    "Mark Rae [MVP]" <> wrote in message news:...
    > "Seguros Catatumbo" <> wrote in message
    > news:...
    >
    >> 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...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    Juan T. Llibre, Sep 14, 2007
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tafs7
    Replies:
    3
    Views:
    3,977
    Alvin Bruney
    Dec 22, 2003
  2. Mark
    Replies:
    0
    Views:
    2,367
  3. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

    =?Utf-8?B?YmNoYXJsZXM=?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    783
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  4. Mark Rae

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,131
    Mark Rae
    May 23, 2006
  5. vikram
    Replies:
    1
    Views:
    834
    Karl Seguin [MVP]
    Oct 4, 2006
Loading...

Share This Page