我关注了这篇文章:
Effective NHibernate Session management for web apps
但是这个:
public void Dispose()
{
app.BeginRequest -= ContextBeginRequest;
app.EndRequest -= ContextEndRequest;
}
给我返回这个错误:
Event handlers can only be bound to HttpApplication events during IHttpModule initialization.
为什么?我可以忽略这些 Dispose
语句吗?
最佳答案
IHttpModule 与应用程序本身紧密耦合,因此当应用程序被销毁时,IHttpModule 也会被销毁。因此无需取消绑定(bind)事件,因此删除该代码是安全的。
关于c# - 事件处理程序只能在 IHttpModule 初始化期间绑定(bind)到 HttpApplication 事件。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6877045/