Results 1 to 7 of 7

Thread: [RESOLVED] Application_Error in global.asax not firing

  1. #1

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Resolved [RESOLVED] Application_Error in global.asax not firing

    Hi,

    I'm trying to handle all my application exceptions inside the global.asax but from some reason it's not firing at all, i never tried to do it before so i guess i'm doing something wrong here...

    here is the code inside the default.aspx page that throw the error:

    Code:
     protected void Page_Load(object sender, EventArgs e)
            {
                throw new Exception();
            }
    and here is the code inside the global.asax:

    Code:
       void Application_Error(object sender, EventArgs e)
            {
                Exception objErr = Server.GetLastError().GetBaseException();
                string err = "Error Caught in Application_Error event\n" +
                        "Error in: " + Request.Url.ToString() +
                        "\nError Message:" + objErr.Message.ToString() +
                        "\nStack Trace:" + objErr.StackTrace.ToString();
                EventLog.WriteEntry("Sample_WebApp", err, EventLogEntryType.Error);
                Server.ClearError();
                Server.Transfer("~/About.aspx");
    
            }
    can someone please lead me to the right direction ?
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Application_Error in global.asax not firing

    Hey,

    I can't think or a reason why that wouldn't be firing.

    Are you trying this on a brand new site, or an existing one? Might be worth trying it on a new site, and make sure that it works there first.

    In case you haven't seen it, there are full details here:

    http://www.15seconds.com/issue/030102.htm

    Gary

  3. #3
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Application_Error in global.asax not firing

    hay, motil
    did you try to add a break point ?
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  4. #4

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Application_Error in global.asax not firing

    Hi, thanks for the answer! i forgot to update this thread, changing it to this:

    Code:
    void Application_Error(object sender, EventArgs e)
            {
                Exception objErr = Server.GetLastError().GetBaseException();
                [.... my own implementation goes here ...] 
                Server.ClearError();
                Server.Transfer("~/About.aspx");
    
            }
    and implementing my own code (the original code was example from microsoft website) fixed the problem.

    Thanks again for the answers!
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Application_Error in global.asax not firing

    Hey,

    Glad to hear that you got it working!

    Remember to mark thread resolved

    Gary

  6. #6

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Application_Error in global.asax not firing

    dang :x
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  7. #7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width