开发者

Application_Error vs Context_Error in asp.net

开发者 https://www.devze.com 2023-01-10 14:05 出处:网络
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)

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)

Like...

public void Init(System.Web.HttpApplication context)

{ cont开发者_开发问答ext.Error += new EventHandler(Context_Error); }

Thanks


In no case is either an impossible approach and these options are not 100% clear cut. 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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消