在ASP.NET 3.5的网站设计模式进行错误处理

在ASP.NET 3.5的网站设计模式进行错误处理

问题描述:

我是比较新的ASP.NET编程和Web编程一般。我们有一个网站,我们最近从.NET 1.1移植到3.5。目前,我们有错误处理方法有两种:要么抓住一个页面上的数据加载过程中的错误,并在页面上显示格式化错误的标签,或重定向到一个一般性的错误页面。这两者都是有点讨厌,因为现在我想重新设计我们是如何错误显示。

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.

我们很快转移到母版页,而我不知道是否有一种方法来打造一个错误处理的控制。我的意思是使用ASP.NET用户控件我已经设计了简单地传递了从服务器返回的错误字符串。如果发生错误,该网页将不显示该内容,而是显示错误控制。这为我们提供了保留的错误(这是我们没有得到与一般错误页)在当前的横幅/导航能力,以及从有到控件添加到每一个aspx页面,我们有让我(我都与使用标签单页系统)。请问像这样有意义吗?最终,我只是想有添加到一个页面中,差错控制,以及所有其他网页直接访问它。这是不是母版页帮助?

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?

谢谢!

用户在Global.asax Application_Error事件引起你的所有未处理的错误 - 你可以在这里记录他们。你不应该输出错误信息到客户端这样的。

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.

使用的customErrors节在web.config来定义你的用户得到一个自定义错误页。

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

您也可以看看使用像 ELMAH ,方便loggin。

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