Solved

Logging all unhandled ASP.NET C# exceptions

Posted on 2008-06-18
2
795 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculating percentage 2 44
Concurrency Error Persistent using Data Grid View Update C# 2 23
How does this modal work? 3 29
dropdownlist in asp.net vb. 3 16
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

740 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