Solved

Logging all unhandled ASP.NET C# exceptions

Posted on 2008-06-18
2
793 Views
Last Modified: 2011-10-03
This is probably quite easy; does anyone know how I can log all unhandled exceptions on my ASP.NET application to a database? Ie, for any unhandled exception, call LogException(Exception e) and then divert user to a page which says "The website has encountered an error - the administrator has been notified".

ASP.NET, C#
0
Comment
Question by:jimstar
2 Comments
 
LVL 16

Accepted Solution

by:
ororiole earned 500 total points
ID: 21818575
Yes indeed. The framework has just such a feature. To your solution right click and add a new item. Add a global.asax file. (I think the dialog calls it a global class file or something). In there you will see an
Applicaiton_Error event handler. Modify it like so, assumeing you have a LogException function:
        protected void Application_Error(object sender, EventArgs e)
        {
            LogException(Server.GetLastError());
            Server.ClearError();
            Server.Transfer("Default2.aspx");
 
        }

Open in new window

0
 
LVL 4

Author Closing Comment

by:jimstar
ID: 31468643
Fantastic, thanks!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question