使用C#处理Web项目异常的方法 [英] Methods to handle exceptions in a web project using C#

查看:91
本文介绍了使用C#处理Web项目异常的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在catch语句中处理异常的最佳方法是什么?目前我们正在将异常消息写入响应对象的写入方法。但是我想要一个解决方案,用户只能得到一个常见的错误消息,发生错误,但是我们必须详细了解错误。我想知道C#中异常处理采用的不同做法。

What is the best way to handle exceptions occurring in catch statements. Currently we are writing the exception message to response object's write method. But I want a solution by which the user will get only a general error message that something has gone wrong but we have to get a detailed description about the error. I would like to know the different practices employed for exception handling in C#.

推荐答案

对于Web项目并防范任何异常按下浏览器,您可以启用运行状况监控并使用自定义错误页面。如果您期待在catch语句中有异常的可能性,那么只需在其中嵌入另一个try catch,以便它可以慷慨解囊。

For the web project and to guard against any exceptions getting pushed down to the browser, you could enable Health Monitoring and also the use of Custom Error Pages. If you are expecting the possibility of an exception inside the catch statement, simply nest another try catch in there so that it falls over graciously.

在global.asax中你也可以可以订阅Application_Error事件,这将被调用为未处理的异常

In the global.asax also you can subscribe to the Application_Error event, which will be called for an unhandled exception

Andrew

ASP中的健康监控.NET: http://www.4guysfromrolla.com/articles/031407-1.aspx

Health Monitoring in ASP.NET : http://www.4guysfromrolla.com/articles/031407-1.aspx

这篇关于使用C#处理Web项目异常的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆