Solved

What is the best way to handle run time errors for a web application?

Posted on 2015-01-07
6
234 Views
Last Modified: 2015-01-08
Hi, I'm using vs2012, asp.net and C#.
Can you suggest or provide url for best practice nowadays to handle run time errors.  I have try catch block.  What's best to do when my application lands in the Catch block.  The best practice on how to log the error or any action I should take.  How to display errors to users.

Thank you.
0
Comment
Question by:lapucca
  • 4
6 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 100 total points
ID: 40536464
You should never display raw exception messages to the user. Aside from potentially being confusing, there is a chance that you could leak sensitive information about your application and/or environment.

As far as logging, you'll need to determine what your organization needs to get out of the logging. At my office, we generate an internal email with the exception details; the user gets presented with a more friendly error message that is to the point, but non-technical. You can also write exceptions to a database or a log file if you prefer. The former can be desirable in terms of maintenance/ease-of-use, but you do incur the cost of going across the network (I'm assuming a database server here, not a local database file). The latter is less desirable because files can fill up a disk, but it would be quicker than going out to a database (not that you would necessarily notice).
0
 

Author Comment

by:lapucca
ID: 40536499
I forgot to mention this is a Intranet web application.  I was thinking about sending out an email and also logging to Window's application event log.  

Can you recommend a a good url/article on how to redirect to an error message?
Thank you.
0
 
LVL 9

Accepted Solution

by:
sudheeshthegreat earned 400 total points
ID: 40537295
Few points:
Dont catch any exceptions unless you plan to do something specific with the exception
For all unexpected errors, let a shared error handler at the application level log the exceptions into the event log. A standard error page should be typically shown to the users for unhandled exceptions.
If you want to send out email alerts based on the error logs, consider doing it separately, and not as part of the error logging process itself. For instance, you could use ELMAH here

Have you read this?
http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/aspnet-error-handling
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:lapucca
ID: 40538826
Hi Sud,
Those are great suggestions.  I've been searching the internet for some documentation on how to use ELMAH and how it logs but haven't sound it. Would you happen to know where is the documentation?  Also, does it only log to database or is there an option to log to Window's application Event log?  I was also looking at "Enterprise Library - Loggin Application" in Nuget and that one seems to offer options for loggin to different destination.  Do you recommend one over the other?   Thank you.
0
 

Author Comment

by:lapucca
ID: 40538839
Okay, I found the site, https://code.google.com/p/elmah/ 
However, it looks like quite a setup for database.  I wonder if it's easier just using the Enterprise Library logging to log into the web server's window's application log?
0
 

Author Closing Comment

by:lapucca
ID: 40538875
I decided to go with Enterprise Library Logging block from MS.  I need to learn about using EL too.  thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

948 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

23 Experts available now in Live!

Get 1:1 Help Now