简体   繁体   English

asp.net中的Application_Error与Context_Error

[英]Application_Error vs Context_Error in asp.net

May be I am confused at the moment and not sure at which point or scenario one should use Application_Error (in Global.asax) or Context_Error (when we implement httpModule) 可能现在让我感到困惑,不确定在哪种情况下应该使用Application_Error(在Global.asax中)或Context_Error(在实现httpModule时)

Like... 喜欢...

public void Init(System.Web.HttpApplication context)

{ context.Error += new EventHandler(Context_Error); {context.Error + = new EventHandler(Context_Error); } }

Thanks 谢谢

In no case is either an impossible approach and these options are not 100% clear cut. 在任何情况下都不是不可能的方法,并且这些选项也不是100%明确的。 There is more than one way to skin a cat, and having different options gives you greater freedom when designing your application. 剥皮猫的方法不只一种,而且在设计应用程序时,有不同的选择可以为您提供更大的自由度。

When you've logic that is specific to your application and relatively local in how it works, then you are probably better off putting it in global.asax. 当您具有针对您的应用程序的特定逻辑,并且在其工作方式方面相对本地化时,那么最好将其放在global.asax中。 It is more likely to need to be changed due to changes in the rest of the application, rather than overall improvements to your entire process. 由于应用程序其余部分的更改,而不是整个过程的整体改进,很有可能需要更改它。

When you've logic you want done in multiple applications on errors, then you are probably better off putting it in a module. 有了逻辑后,您想在多个应用程序中对错误进行处理,那么最好将其放入模块中。 It is more likely to need to be changed due to changes to your overall process, rather than specific to that application. 由于更改了整个流程,而不是特定于该应用程序,因此很有可能需要更改它。

If you want behaviour to be "pluggable" without recompiling, then you need to do it in a module. 如果您希望行为是“可插入的”而无需重新编译,则需要在模块中进行。 However, there are other means by which functionality can be turned on or off without recompiling (configuration settings), so even this isn't cut-and-dried. 但是,还有其他方法可以打开或关闭功能而无需重新编译(配置设置),因此即使这样也不会被剪切和干燥。

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

相关问题 如何从ASP.NET MVC 2中的Application_Error重定向? - How to redirect from Application_Error in ASP.NET MVC 2? 如何在Application_Error()中知道asp.net中的请求是ajax - How to know if the request is ajax in asp.net in Application_Error() ASP.NET MVC如何在不重写URL的情况下处理Application_Error的404错误 - ASP.NET MVC how to handle 404 error from Application_Error without rewriting the URL 使用路由的ASP.NET 4 Web窗体-错误时未调用Application_Error - ASP.NET 4 Web Forms Using Routing - Application_Error Not Called on Error 即使Application_Error完成,asp.net应用程序仍保持运行 - asp.net application keeps running even after Application_Error finishes Application_Error中的ASP.net Global.asax错误详细信息 - ASP.net Global.asax error detail in Application_Error ASP.NET MVC自定义错误处理Application_Error Global.asax? - ASP.NET MVC Custom Error Handling Application_Error Global.asax? 您是否应该在ASP.NET MVC的global.asax中使用方法Application_Error? - Should you use the method Application_Error in your global.asax in ASP.NET MVC? 在ASP.NET MVC4中,application_error哪里去了? - In ASP.NET MVC4, where has application_error gone? ASP.NET Web 服务忽略 Application_Error 和 UnhandledException 事件 - ASP.NET Web service ignoring Application_Error and UnhandledException event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM