当 HttpModule Init 方法在 ASP.NET 集成模式下运行时?

发布于 2024-12-22 00:13:36 字数 378 浏览 2 评论 0原文

我编写了一个 HttpModule,它是 NHibernate Session Provider。它只是在 HttpModule 的 Init 方法中打开一个 SessionFactory 并在 BeginRequest 中获取一个新的 Session 并在 EndRequest 中关闭它。另一方面,我在 Global.asax 中编写了一个方法,该方法使用来自此 HttpModule 的名为 GetData 的会话。我在 Global.asax 的 Init 方法中运行该方法(GetData)。问题是当我在集成模式下使用 HttpModule 时,我的 HttpModule 在运行 Global.asax 的 Init 方法之前似乎没有初始化。

我搜索了这些方法的运行顺序和事件的生命周期,但没有发现任何有用的信息!

I've written an HttpModule that is an NHibernate Session Provider. It simply opens a SessionFactory in Init method of HttpModule and gets a new Session in BeginRequest and closes it in EndRequest. At the other side, I wrote a method in Global.asax that uses a session from this HttpModule named GetData. I run that method (GetData) in Init method of Global.asax. The problem is when I use my HttpModule in integrated mode it seems that my HttpModule does not Initialize before running Init method of Global.asax.

I've searched for order of running these methods and life cycle of events but nothing useful found!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟花易冷人易散 2024-12-29 00:13:36

在 IIS 7.x 中,模块和处理程序应在 web.config 文件的 system.webServer xml 元素中注册。

查看此 MSDN 文章:

In IIS 7.x, modules and handlers should be registered within system.webServer xml element in your web.config file.

Check this MSDN article:

听风吹 2024-12-29 00:13:36

ASP.NET 对于何时相互调用 HttpModule Init() 方法不提供任何保证(与静态初始值设定项不同)。一般来说,Init() 方法应该用于连接事件处理程序,并且任何“实际工作”都应该在事件处理程序中完成。

在继续下一个事件之前,从所有 HttpModule(包括 Global.asax)调用特定事件的所有已注册事件处理程序 - 因此您可以通过这种方式控制顺序。

ASP.NET does not provide any guarantees on when HttpModule Init() methods are called with respect to one another (not unlike static initializers). In general, the Init() methods should be used to wire up event handlers, and any "real work" should be done in the event handlers.

All registered event handlers for a specific event are called from all HttpModules, including Global.asax, before moving on to the next event -- so you have control over order that way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文