事件处理程序只能在IHttpModule初始化期间绑定到HttpApplication事件。

时间:2011-07-29 17:55:05

标签: c# .net asp.net

我遵循了这篇文章:

Effective NHibernate Session management for web apps

但是这个:

public void Dispose()
{
    app.BeginRequest -= ContextBeginRequest;
    app.EndRequest -= ContextEndRequest;
}

给我这个错误:

  

事件处理程序只能绑定到HttpApplication事件   IHttpModule初始化。

为什么呢?我可以忽略这些Dispose陈述吗?

1 个答案:

答案 0 :(得分:3)

IHttpModule与应用程序本身紧密耦合,因此当应用程序被销毁时,IHttpModule也是如此。因此,没有必要取消绑定事件,因此删除该代码是安全的。