[英]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.