views:

133

answers:

1

I am relatively new to ASP.NET programming, and web programming in general. We have a site we recently ported from .NET 1.1 to 3.5. Currently we have two methods of error handling: either catching the error during data load on a page and displaying the formatted error in a label on the page, or redirecting to a generic error page. Both of these are somewhat annoying, as right now I'm trying to redesign how our errors are displayed.

We are soon moving to Master pages, and I'm wondering if there is a way to "build in" an error handling control. What I mean by this is using a ASP.NET user control I've designed that simply gets passed the error string returned from the server. If an error occurs, the page would not display the content, and instead display the error control. This provides us with the ability to retain the current banner/navigation during an error (which we don't get with the generic error page), as well as keeping me from having to add the control to every aspx page we have (which I have to do with using the label-per-page system). Does something like this make sense? Ultimately I just want to have the error control added to a single page, and all other pages have access to it directly. Is this something Master pages help with?

Thanks!

+2  A: 

User the application_error event in the global.asax to catch all your unhandled errors - you can log them here. You shouldn't be outputting error messages to the client like this.

Use the CustomErrors section in the web.config to define a custom error page for your users to get.

You could also look at using something like ELMAH for easy loggin.

Paddy
Thanks for the link to ELMAH, we may use something like this. The real issue we have is not with unhandled exceptions, its more with our server returning error's during a data retrieval. And how to design the site so every page displays the error in the same way to the user.
Kevin
OK, you could look at providing a method on your master page to set the text of your error label, this might be a way of writing out explanatory error messages consistently.
Paddy