Global.asax Error Handling to a dbase


Just wandering if anyone knows of some good articles to read about error handling with the global.asax file (using 2.0 by the way). What I'd like to implement in my application is a simple error logging system whereby it will catch every error and write it to a dbase. I've got a rough idea on how to implement but would like some extra guidelines. Also, is it possible to reference a class in the global.asax file. What I'd like is to call my function in the class as opposed to actually write the whole script in the global.asax file, how can I achieve this. Cheers. Smile

5/24/2007 2:49:01 PM 12495 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 47

 Absolutely. While I don't have any paticular article for you to read, here is snippet of what we did in our software, in essence, catch the error in Application_Error method, get the error via Server.GetLastError() and if you have a specific error page that you want to display other than the others you defined in the <customeError> section of the web.config, you can use server.transfer and point to whichever url you would like.

Btw, we use log4net network to log exceptions and "ApplicationErrorsManager()" is our custom class.

Hope it gets you started.

public class Global : System.Web.HttpApplication
    private static readonly ILog log = LogManager.GetLogger(typeof(Global));

    public Global()
        // TODO: Add constructor logic here

    void Application_Start(object sender, EventArgs e)
        // Code that runs on application startup

    void Application_End(object sender, EventArgs e)
        //  Code that runs on application shutdown



    void Application_Error(object sender, EventArgs e)

        Exception ex = Server.GetLastError();
        int i = new ApplicationErrorsManager().SaveApplicationError(ex);
        Session["ApplicationErrorID"] = i;
        log.Debug("Application error in id in global :" + i);

    void Session_Start(object sender, EventArgs e)
        // Code that runs when a new session is started


    void Session_End(object sender, EventArgs e)
        // Code that runs when a session ends.
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer
        // or SQLServer, the event is not raised.


Liming Xu
Jumptree ASP.NET 2.0 Project Management - With Source Code, Free to Non Profit Org and Effectively Manage Projects/Tasks/Milestones
5/24/2007 3:30:10 PM

Similar Artilces:

Avoiding nasty-looking .Net errors with bad urls, error handling in web.config and global.aspx.vb
It's quite easy to generate nasty looking errors in DNN by eg entering &tabid=rubbish on the url or asking for a file that doesn't exist. Firstly, I'd recommend a custom error page (though not sure what should be in it) and note that you can specify a special page eg for 404 - page not found, which you could make redirect to root, or in my case, I look for page in portal upload directory then redirect to &tabname=404 to allow per-portal custom 404 pages. &lt;customErrors mode="RemoteOnly" defaultRedirect="/error.htm" > &lt;error st...

Error handling in Application_Error global.asax and web.config
I have an error handling code in the event Application_Error of global.asax. I also have custom error pages defined in web.config as e.g.: <customErrors defaultRedirect=”ErrorPage.htm” mode=”On” > <error statusCode=”404” redirect=”ErrorPage404.htm”/> </customErrors> The problem is that the error handling code in Application_Error stops the program and the ErrorPage404.htm is not shown if user enters wrong URL. How can I make Application_Error ignore errors defined in the web.config? Thank you. ...

error handling in global.asax (.net 2.0)
Does anyone have a nice, clean template for global error handling for 2.0? I have been going through the available messages in Server.GetLastError() and noticed there are a few things missing. For one there is no http error code (404, 403b, etc..). I tried adding the error code but only could get the error code for the page that displayed the error report (200) and not the page that caused the error (404). Is this possible? I have the global.asax file set to add to the event log and send and email when an error occurs. I just don't know what I should put in the message/log, Any he...

global.asax & web.config
I want to run some logic in the global.asax file when an error happens, then redirect the user to a custom error page based off of the error type. I can easily redirect them with a web.config file, but if I run logic in the global.asax file it doesn't do the redirect. My questions are: 1) Is the web.config supposed to take over after the global.asax runs some logic? if not 2) Is there a way to determine the type of error in the global.asax file using Server.GetLastError Thanks I don't know about your first questions, from your description it seems that the Web.Config i...

Global Error Handling
I am about to add global error handling to my application and have come across a couple of articles that discuss different ways of handling the problem, mainly: - Using a HttpModule - Using the global.asax Are there any reasons why one method would be better than the other? As the guy who wrote the former, I'm here to say: there's really (almost) no difference at all. The global.asax method is catching the Error event on Application with a method named Application_Error(). My method is catching the Error event on Application by using pure code and hooking it explicitl...

Global Error Handling (global.asax) and HttpResponse.StatusCode Property
Hey How can I use the HttpResponse.StatusCode Property in the Global.asax? I have a global error handling at the moment... Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) Try ' Set default values Session("ErrorMessage") = "No error information was available" Session("ExceptionType") = String.Empty Session("PageErrorOccured") = Request.CurrentExecutionFilePath Session("StackTrace") = String.Empty ' Catch the last exception thrown Dim lastError As Exceptio...

Error handling in global.asax
Is it possible when using the Server.GetLastError() method to retrieve the file name, row number and column number from where the error originated? You know how when you have an error and .net outputs about 5 lines (the problem line in the middle) and it tells you exactly where the error originated. That's what I would like to be able to do. The GetLastError() method return an Exception object. The Exception class has several properties, like StackTrace, Message etc. that may be displayed. I think this is all that can be done easily.Yevgeny Menaker And the line numbers are only availa...

Error handling with global.asax
I am using the Application_Error method within the global.asax file. I would like to have different exception handlers for different types, but I cannot find away to extract the type from the exception object returns from server.getlasterror() method.  Can anyone shine any light on this for me? Any help much apreciated You can check the exception type returned by Server.GetLastError(). However, most of the time (in Application_Error) this will be of type HttpUnhandledException. If you want to find out what the underlying exception was, simply check the InnerException property e....

how to use the global.asax for error handling
hi, how to use the global.asax for error handling. i used a global.asax file for handling error.but the problem is that i used a try catch , & a throw new Execption(), but the problem is that i whenever a error comes its getting caught by try catch & the cursor gets stack up in the catch, if i press f5 then it proceeds to the global.asax .... Please tell me how to use it... my purpose is  that i need a common error handler with log ... error  log works whenever the cursor comes to the  gloabal.asax, error log work... Could anyo...

Error Handling in global.asax C#
Hi all, I am trying to create (newbie to .net) - a global.asax.cs file to handle errors that will be emailed to me :)But i am not getting anything sent out to be when i forcefully try and create an error to test it (removed a DB so .net cant find it)..Can anyone help please with the code?<code>using System.Web; using System.Web.Mail; using System.Text; using System.Web.SessionState; public class Global : System.Web.HttpApplication namespace meepv2{  public Global()  {    base.New();    InitializeComponent();  }  private System.ComponentMod...

Custom Error Handling without Global.asax
I have a web project that was developed in WebMatrix, there is very little code behind most of the code is right on the aspx pages. I am trying to retrofit Custom error pages. The problem I am having is that I do not have a Global.asax page, as a result, I have not figured out a way to handle exceptions. From what I can gather from other posts on this forum the Exception throw is cleared by the time it gets to my defaultRedirect page. So I can't read Server.GetLastError to get the exception and store it in a database. So my questions are, is there a way to create a Global.asax file that w...

Web.config and global.asax error hanndling
Hi Could any body explain what is the difference between we.config error handling and global.asax error handling   In web.config, you're just specifying what you want to happen with the error for display purposes mainly: Display the exception to everyone, display the exception only on the server, or redirect to a custom error page. In Global.asax you tell the application what to do on when an exception is raised (i.e. send out an email, log the exception in a database). Does that answer your question?Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow ...

Handling runtime errors via global.asax
Hi people, I am trying to handle errors at the application level by creating an Application_Error function in the global.asax file. It looks like the following: ------------------------------------------------- <%@ Application Language="C#" %><script language="C#" runat="server"> protected void Application_Error(Object sender, EventArgs e){    Response.Redirect("ErrorPage.aspx");} ------------------------------------------------- To test this I am generating a runtime error (via the code int x = 9999999999999999 * 9999999999999999;) in my default page. Howeve...

error handling
I want to handle errors with a global exception handler.  Within my Application_Error event, how can I get the original IP address that made the request ?  Try using HttpContext.Current.Request.UserHostAddress in your error handler.If this post answered your question please remember to 'Mark as Answer'!...

Web resources about - Global.asax Error Handling to a dbase -

Anchor handling tug supply vessel - Wikipedia, the free encyclopedia
Anchor Handling Tug Supply (AHTS) vessels are mainly built to handle anchors for oil rigs , tow them to location, anchor them up and, in a few ...

New Facebook SDK For IOS Adds Automatic Error Handling, Improved Login UI
... software-development kit for iOS is now available for download , with significant enhancements including a beta test of automatic error handling ...

Handling Disputes and Refunds
Handling Disputes and Refunds

Facebook Shares Stats on How Users are Handling the Latest Privacy Changes
Facebook’s traffic has yet to be affected by the aggressive privacy changes it made at the beginning of December, from what data we can see — ...

Handling five billion sessi
... that provides app developers with reliable, real-time and actionable insights into their mobile apps. Skip to main content Sign in Search Handling ...

Customer Service Handling
This group is for people in customer service profession facing the customer either in person or over phone.

Wrap Camera HD - Ultimate Picture Editor with Unique Paper Handling on the App Store on iTunes
Get Wrap Camera HD - Ultimate Picture Editor with Unique Paper Handling on the App Store. See screenshots and ratings, and read customer reviews. ...

Dead domain handling page - Flickr - Photo Sharing!
Explore anearthling's photos on Flickr. anearthling has uploaded 1692 photos to Flickr.

Frank Rich Talks New York Media, Handling Criticism - Media Beat (2 of 3) - YouTube
In the second part of our three-part "Media Beat" interview with him, Frank Rich talks about leaving The New York Times to join New York magazine, ...

34% Rate Obama’s Handling of Government Spending As Good or Excellent
Voters continue to question President Obama's handling of issues related to government spending and taxes. A new Rasmussen Reports national telephone ...

Resources last updated: 11/26/2015 6:24:05 PM