简体   繁体   English

处理asp.net中未处理的异常

[英]Handle unhandled exceptions in asp.net

How can we prevent page crash in asp.net? 如何防止asp.net中的网页崩溃? Is there any generic function or place like global.asax where we specify a file to redirect to when an unhanded exception occurs? 是否有通用函数或地方(例如global.asax)在其中指定了当发生未处理的异常时重定向到的文件? (like we redirect to a specified page when 404 page not found exception occurs? (例如,当404页面未找到异常发生时,我们重定向到指定页面吗?

<customErrors> doesn't prevent your pages from "crashing". <customErrors>不会阻止您的页面“崩溃”。 It just allows you to apologize to your users when the page does crash. 它只是让你当页面没有崩溃道歉,你的用户。

You should be examining the Application event log for messages from the source "ASP.NET <version> ". 您应该检查应用程序事件日志中是否有来自源“ ASP.NET <version> ”的消息。 These will include details of any exceptions your code has been generating and not handling. 这些将包含您的代码已生成但未处理的所有异常的详细信息。 You need to fix these, as every one of these indicates that your users were not able to do what they came to your site to do. 您需要解决这些问题,因为每一项都表明您的用户无法执行访问您网站的操作。

You can do it in Global.asax or you can set up custom error pages in web.config. 您可以在Global.asax中执行此操作,也可以在web.config中设置自定义错误页面。

ASP.NET Custom Error Pages ASP.NET自定义错误页面

How can we prevent page crash in asp.net? 如何防止asp.net中的网页崩溃?

As Mal said, "If it crashes, you crashed it". 正如Mal所说:“如果崩溃,则将其崩溃”。 The only way to "prevent" crashes is by carefully writing your code, testing, etc, as with any program. 防止崩溃的唯一方法是像对待任何程序一样,仔细编写代码,进行测试等。

To display a nice error page, check out the <customErrors> element in your web.config. 要显示一个不错的错误页面,请检查web.config中的<customErrors>元素。 MSDN docs here . MSDN文档在这里 Plenty of articles around if you google for 'customErrors'. 如果您在Google上搜索“ customErrors”,则有很多文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM