问题描述
我写一个ASP.NET网站,这对我来说是一个新的框架。我发现,我有我的字面上codebehind的每一个方法的try / catch块。所有这些try / catch块做的是捕获异常,然后弹出一个错误信息给用户。是不是有一些在ASP.NET全局错误处理的?值得注意的是我的错误处理中的控制(ASCX)的页面,我想一个办法简单地让每个ASCX来处理自己的错误,而无须强制所有的错误只是处理单个母版页或重定向...
I am writing an ASP.NET website, which is a new framework for me. I find that I have a try/catch block in literally every method of my codebehind. All these try/catch blocks do is catch the exception and then pop-up an error message to the user. Isn't there some sort of global error handler in ASP.NET? It's worth noting that my error handling is within control (ASCX) pages, and I would like a way to simply get each ASCX to handle its own errors without forcing all error handling just to a single master page or a redirect...
感谢以下建议。我曾尝试Page_Error事件,因为它似乎是一个积极的选择。我跑的测试,我的例外情形现在通过Page_Error事件运行,但事情的倒不工作...我使用'Content.ClearError()在我Page_Error事件的结束,但是,客户端浏览器仍与未处理的结束PageRequestManagerServerErrorException。任何建议?如果有帮助,我使用Telerik的,并试图弹出一个开放的,只要radalert发生错误...
Thanks for advice below. I did try Page_Error as it seems a positive option. I ran a test and my exceptions do now run through Page_Error, however thing's ain't quite working... I use 'Content.ClearError()' at the end of my Page_Error, however, the client browser still ends up with an unhandled PageRequestManagerServerErrorException. Any advice? If it helps, I am using Telerik and trying to pop open a radalert whenever an error occurs...
推荐答案
您可以实现在页级的 Page_Error事件
事件处理程序。这听起来像是一个完美的适合你的要求。
You could implement the Page_Error
Event handler at the page level. That sounds like the perfect fit for what you asked.
另外,更在全球范围的应用程序级,您可以尝试的Application_Error
事件处理在Global.asax中。
Otherwise, more globally on the application level, you may try the Application_Error
Event Handler in Global.asax.
另请参阅里面包含了很多对asp.net处理错误信息。
See also http://msdn.microsoft.com/en-us/library/aa479319.aspx which contains a lot of information on error handling in asp.net.
这篇关于避免的try / catch地狱在我的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!