c# - 事件处理程序只能在 IHttpModule 初始化期间绑定(bind)到 HttpApplication 事件。

标签 c# .net asp.net

我关注了这篇文章:

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/

相关文章:

c# - DateTime.UtcNow 提前 4 小时

c# - 如何使 Json.NET 成为默认的 Json 序列化程序

c++ - 可以通过编程方式控制进入笔记本电脑的交流电源吗?

c# - 通过 ODBC 查询系统间缓存

c# - 两个日期时间变量何时相等?

c# - 不正确的 Lambda 表达式缩进

c# - 授权具有角色的属性不起作用?

c# - 如何对 Windows 服务进行单元测试?

asp.net - AJAX 调用返回页面 HTML/未命中页面方法是 ASP.Net(无 MVC 或 Json)

c# - Javascript不获取隐藏文本框值?