Solved

Logging all unhandled ASP.NET C# exceptions

Posted on 2008-06-18
2
789 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
Comment Utility
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
Comment Utility
Fantastic, thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now