- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我只是在 Web 应用程序中记录异常详细信息,我真的需要为每一层添加异常处理逻辑吗?为什么不让它们全部通过堆栈跟踪冒泡到 global.asax 并将它们记录在那里?
最佳答案
我建议不要在应用程序的任何层中使用任何异常处理逻辑,除非:
当然,异常 - 无论它们是否致命,或者是否应该“忽略” - 都需要记录并通知开发人员。最好通过 Application.Error
事件的事件处理程序来处理。是的,这可以在 Global.asax 中完成,但我认为使用基于 HTTP 模块的方法更干净,或者 Health Monitoring或ELMAH .
我写了一篇关于这个主题的文章,我想推荐给您 - Exception Handling Advice for ASP.NET Web Applications 。以下是文章摘要:
My advice for handling exceptions in an ASP.NET application can be boiled down to the following guidelines:
(a) Create and use a meaningful custom error page.
(b) In general, do not catch exceptions. Let them bubble up to the ASP.NET runtime. Some cases where catching an exception makes sense include:
When there is a plausible way to recover from the exception by performing some alternative logic,
When a peripheral part of the application's workflow throws and exception and that exception should not derail the entire application, and
When you need to include additional information with the exception by throwing a new exception that has the original exception as its inner exception.
(c) Log all exceptions to some persistent store and use email (or some other medium) to notify developers when an exception occurs in production. Consider using ELMAH or ASP.NET's built-in Health Monitoring system to facilitate this process.
关于asp.net - 我应该在 global.asax 中捕获所有异常吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4307683/
我正在开发 ASP.NET Web 应用程序,对于未处理的异常,我正在使用Global.asax 文件 我在其中编写了将错误日志写为 的逻辑 Sub Application_Error(ByVal s
Tell me about the difference between global.asax and global.asax.cs ? 和 If i click the both file in
在我的本地发布文件夹中,我有 Global.asax 和 Global.asax.cs,其中 Global.asax 未更新(日期为一个月前)和 Global.asax .cs 已更新。 我检查了 G
我在 2 台开发计算机上安装了一个 ASP.NET MVC 应用程序。该应用程序在两台计算机上运行良好(使用本地 IIS)。直到最近,我经常从一台或另一台计算机在生产服务器上发布而没有问题。从3周前开
我正在尝试将代码添加到我没有源代码的第 3 方 ASP.NET Web 应用程序的 application_start 事件。我通过从供应商的 Global 类继承来做到这一点。这是代码(注意“new
在我们使用 WebAPI 构建“简单”API 的冒险过程中,我们遇到了与任何项目一样的问题,但是我无法找到可以解释以下行为的任何此类资源:细节 : 带有 Update 2 的 Visual Studi
我有一个仅适用于 Firefox 的登录页面。它不适用于任何其他浏览器。 当我检查事件日志时,我看到“响应在当前上下文中不可用”。它告诉我错误在 global.asax 文件中,在 response.
我构建了一个包含 Global.asax 文件的 WCF 应用程序。我添加了 AspNetCompatibilityRequirements(RequirementsMode = AspNetComp
有一个Global.asax asp.net 应用程序根目录中的文件。 扩展命名背后的原因是什么? 我可以创建其他文件来使用这个扩展吗?出于什么目的? 最佳答案 Global.asax分机 stand
是否可以在 global.asax 中捕获回收事件? 我知道 Application_End 会被触发,但有没有办法知道它是由应用程序池的回收触发的? 谢谢,Lieven Cardoen 又名 Joh
我想创建一个全局选项,当 REST 调用包含 &format=json 以将响应输出为 JSON 字符串时。 如果我在我的方法中输入以下字符串,它会起作用: WebOperationContext.C
我计划使用 System.Data 包的全局导入。在我添加之后 在 global.asax 的标记中 在我的一个类中,我删除了代码顶部的“使用 System.Data”。 我构建了 global.a
我在asp.net和C#中有Web应用程序 我试图处理异常,如果它们在此应用程序内的任何地方发生。 例如,假设行为应为if和发生这种异常 //generate your fictional excep
我无法调试 global.asax 文件! 我在 Application_Start() 方法中有一些代码,但是当我在该方法中设置断点时,它会被忽略! 这正常吗? 最佳答案 中断 Applicatio
我试图从数据库中检查用户是否属于某人的好友列表并相应地重定向他。 我在 Global Asax 调用的路由处理程序中执行此操作。 我只想知道如何在路由处理程序类(或全局 asax)中获取用户名(从登录
我添加了一个 global.asax 文件,后来我决定不需要它,所以我将它从项目中排除,但现在我在尝试运行我的项目时遇到解析器错误。 下面是 View 上显示的错误: Line 1: 发生了什么以
我想在我的 global.asax 中使用带有 response.redirecttoroute 的自定义路由,但它不起作用。我的 RouteConfig 中有以下内容: routes.MapRout
全局 asax 文件有什么用?我希望声明将在整个应用程序页面中使用的特定于用户的对象字典。我在哪里声明这个字典? 谢谢。 最佳答案 Global.asax 包含一个代表整个应用程序的类。如果您的词典是
我正在开发一个 HttpModule 并使用 Global.asax。我开发了一个派生自 HttpApplication 的类,但我的类的 Application_Start 方法从不执行(我在 Ap
是否可以将 Global.asax 文件嵌入到程序集中?当前,它表示为 Web 根目录中的一个文件。但我想将它作为资源存储在程序集中。 最佳答案 我不确定。您是否尝试过将 Build Action 设
我是一名优秀的程序员,十分优秀!