Exception handling in ASP.NET Webforms(ASP.NET Webforms 中的异常处理)
问题描述
在 ASP.NET Webforms 中处理异常的首选方法是什么?
What is the preferred method for handling exceptions in ASP.NET Webforms?
您有在 web.config 级别添加(我认为)的 Page_Error 方法,当发生错误时,整个站点都会被重定向到那里.
You have the Page_Error method that you add (I think) at web.config level, and the entire site gets redirected there when an error occurs.
这是否意味着您不应该在 webforms 应用程序的任何地方使用 try-catch?(假设您不想隐藏任何错误)
Does that mean you shouldn't use try-catch anywhere in a webforms application? (Assuming you don't want to hide any errors)
推荐答案
只捕获您可以处理的错误.如果您可以以允许页面继续加载的方式处理它们,那么就这样做.任何其他会破坏页面的异常都不应该在任何控件或页面中处理,因为无论如何你都无法做任何事情.让它转到 global.asax 处理程序并确保记录异常.
Only catch the errors you can handle. If you can handle them in a manner that allows the page to continue loading then do so. Any other exception that would wreck the page should not be handled in any control or page as you would not be able to do anything anyways. Let it go to the global.asax handler and make sure you log the exception.
这篇关于ASP.NET Webforms 中的异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.NET Webforms 中的异常处理
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
