Solved

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

Posted on 2015-01-07
6
228 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 74

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

22 Experts available now in Live!

Get 1:1 Help Now