使用EndRequest事件关闭NHibernate的会议与IIS 7 [英] Using EndRequest Event to close NHibernate Session with IIS 7

查看:144
本文介绍了使用EndRequest事件关闭NHibernate的会议与IIS 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个新的ASP.NET项目NHibernate的,和正在运行成什么样我认为是奇怪的行为。我试图用一个HttpModule捕捉EndRequest事件并关闭会话来管理我的会议。这是工作的罚款,但是,EndRequest事件触发后,我得到在尝试读取从我的对象的属性,是延迟加载自定义控件之一的onload事件异常。我得到一个异常,说明无法初始化懒洋洋地收集,没有会话或会话被关闭。谈到延迟加载了这些属性不解决问题,而且是一个可以接受的解决方案。但是,这似乎是想对我一直以为是真的。

I am using NHibernate on a new ASP.NET project, and am running into what I believe to be strange behavior. I am attempting to manage my session by using an HttpModule to catch the EndRequest event and close the session. This is working fine, however, after the EndRequest event fires, I am getting an exception in the OnLoad event of one of my custom controls that is attempting to read a Property from my object that is lazy loaded. I get an exception stating 'failed to lazily initialize a collection, no session or session was closed'. Turning lazy load off for these properties does fix the problem, and is an acceptable solution. But this seems to be going against what I always thought to be true.

我假设OnLoad事件和所有服务器端的处理将在该EndRequest触发点来完成。这也是我用IIS 7的一个项目的第一次。这是行为的原因是什么?什么是预期的行为?

I would assume that the OnLoad event and all server side processing would be done at the point that EndRequest is fired. This is also the first time that I have used IIS 7 on a project. Is this a reason for the behavior? What is the expected behavior?

推荐答案

我刚刚有了一个掌掴的额头'的时刻。尽管我其实部署到IIS 7服务器,我一直在使用VS 2008内置的Web服务器(卡西尼)调试。卡西尼通过ASP.NET管道的所有请求,IIS没有。这是造成了一个图像文件或JavaScript文件的请求(或任何其他静态资源)关闭我的NHibernate的会议之前,我其实是想它应该关闭。

I just had a 'palm slaps forehead' moment. Despite the fact that I am in fact deploying to an IIS 7 server, I have been debugging using the VS 2008 Built in Web server (Casini). Casini passes all requests through the ASP.NET pipeline, IIS does not. This was causing a request for an image file or javascript file (or any other static resource) to close my NHibernate session before I was actually thinking it should close.

感谢资源列表中,我肯定会考虑他们。

Thanks for the list of resources, I will certainly look into them.

这篇关于使用EndRequest事件关闭NHibernate的会议与IIS 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆