global.asax Application_Error not firing on forced exception?? - DOTNET

This is a discussion on global.asax Application_Error not firing on forced exception?? - DOTNET ; I'm forcing an error/exception in one page as follows Protected Overrides Sub OnLoad(ByVal e As EventArgs) Dim badthing As New Exception("XXX") Throw badthing End Sub And attempting to set a session variable to that error in the global.asax file as ...

+ Reply to Thread
Results 1 to 2 of 2

global.asax Application_Error not firing on forced exception??

  1. Default global.asax Application_Error not firing on forced exception??

    I'm forcing an error/exception in one page as follows


    Protected Overrides Sub OnLoad(ByVal e As EventArgs)
    Dim badthing As New Exception("XXX")
    Throw badthing
    End Sub

    And attempting to set a session variable to that error in the
    global.asax file as follows:

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    Dim ex As Exception = Server.GetLastError()
    Session("LASTERROR") = ex.Message.ToString +
    ex.InnerException.Message.ToString + ex.Source.ToString
    Session("xx") = "xx"
    ' Code that runs when an unhandled error occurs
    End Sub

    in my web.config I also have customerrors turned on and redirecting to
    an errorpage.aspx page where I want to read that session variable:

    The exception happens and I am taken to my errors page, but no sign of
    the session variable. If I debug in VS.NET I notice it never makes it
    to that subroutine in the global.asax file.


    Am I missing something? Could it be that I have no application name?
    Is this an IIS thing maybe?

    Thanks for any help or information.



  2. Default Re: global.asax Application_Error not firing on forced exception??

    re:
    !> The exception happens and I am taken to my errors page, but no sign of the session variable.
    !> Am I missing something?

    You need to call Server.ClearError() after setting your session variables.

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    Dim ex As Exception = Server.GetLastError()
    Session("LASTERROR") = ex.Message.ToString + ex.InnerException.Message.ToString + ex.Source.ToString
    Session("xx") = "xx"
    Server.ClearError()
    End Sub




    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/
    ======================================
    "jobs" <jobs@webdos.com> wrote in message news:07f9d6de-8278-414e-a880-e49a58e29491@c30g2000hsa.googlegroups.com...
    > I'm forcing an error/exception in one page as follows
    >
    >
    > Protected Overrides Sub OnLoad(ByVal e As EventArgs)
    > Dim badthing As New Exception("XXX")
    > Throw badthing
    > End Sub
    >
    > And attempting to set a session variable to that error in the
    > global.asax file as follows:
    >
    > Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    > Dim ex As Exception = Server.GetLastError()
    > Session("LASTERROR") = ex.Message.ToString +
    > ex.InnerException.Message.ToString + ex.Source.ToString
    > Session("xx") = "xx"
    > ' Code that runs when an unhandled error occurs
    > End Sub
    >
    > in my web.config I also have customerrors turned on and redirecting to
    > an errorpage.aspx page where I want to read that session variable:
    >
    > The exception happens and I am taken to my errors page, but no sign of
    > the session variable. If I debug in VS.NET I notice it never makes it
    > to that subroutine in the global.asax file.
    >
    >
    > Am I missing something? Could it be that I have no application name?
    > Is this an IIS thing maybe?
    >
    > Thanks for any help or information.
    >
    >




+ Reply to Thread

Similar Threads

  1. using global.asax.vb for defining global parameters
    By Application Development in forum DOTNET
    Replies: 5
    Last Post: 11-25-2007, 07:59 PM
  2. Global.asax
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 10-09-2007, 09:07 AM
  3. HTTP_REFERER is null on global.asax's Application_Error
    By Application Development in forum DOTNET
    Replies: 16
    Last Post: 09-14-2007, 04:32 AM
  4. global.asax in ASP.NET 2.0 ???
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 08-13-2007, 11:25 AM
  5. Global.asax
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 11-30-2005, 09:47 AM