ASP.NET MVC3 中整合 NHibernate3.3、Spring.NET2.0 时 Session 关闭问题
一、问题描述
在向ASP.NET MVC中整合NHibernate、Spring.NET后,如下管理员与角色关系:
类public class Admin
{
public virtual string Username { get; set; }
public virtual string Password { get; set; }
public virtual string Name { get; set; }
public virtual DateTime AddTime { get; set; }
public virtual DateTime? LastTime { get; set; }
public virtual string LastIP { get; set; }
public virtual byte ErrorCount { get; set; }
public virtual bool State { get; set; }
public virtual Role Role { get; set; }
} public class Role
{
public virtual string Code { get; set; }
public virtual string Name { get; set; }
public virtual bool State { get; set; }
public virtual short Sort { get; set; }
}
在Web层获取Admin实体后,由于Role属性配置为延迟加载机制,再访问Role属性时,提示 Session 已关闭。
网上也有较多的文章来解决这个问题,此文也整理一下,但不适应于IIS7.5版本。最终,在一国外网站中找到了问题的解决办法(http://stackoverflow.com/questions/6060386/spring-net-and-mvc3-on-iis7-session-scope-behaviour)。
二、解决办法
解决这个问题,需要配置Hibernate中Session的维护由Spring来管理,对于IIS6,Web.config如下:
IIS6<appSettings>
<add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName" value="NHibernateSessionFactory"/>
............
</appSettings>
<system.web>
<httpModules>
<add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate33"/>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
............
</system.web>
IIS7<appSettings>
<add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName" value="NHibernateSessionFactory"/>
......
</appSettings>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" >
<add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate33"/>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</modules>
.......
</system.webServer>
这里需要注意Spring.NET的版本,我这里用的是适用于NHibernate3.3的dll。
ASP.NET MVC3 中整合 NHibernate3.3、Spring.NET2.0 时 Session 关闭问题的更多相关文章
- ASP.NET MVC3 中整合 NHibernate3.3、Spring.NET2.0 使用AOP执行事务处理
方法1 <object id="ServiceOperation" type="Spring.Aop.Support.SdkRegularExpressionMet ...
- ASP.NET MVC3中Model验证
原文:ASP.NET MVC3中Model验证 概述 上节我们学习了Model的数据在界面之间的传递,但是很多时候,我们在数据传递的时候为了确保数据的有效性,不得不给Model的相关属性做基本的数据验 ...
- 在ASP.NET MVC3 中利用Jsonp跨域访问
在ASP.NET MVC3 中利用Jsonp跨域访问 在信息系统开发的时,根据相关业务逻辑难免会多系统之间互相登录.一般情况下我们需要在多系统之间使用多个用户名和密码.这样客户就需要在多个系统之间重复 ...
- Asp.net MVC3 中,动态添加filter
Asp.net MVC3 中,动态添加filter filter是attribute,不支持泛型,传入的参数必须是固定的值.总之很受attribute本身的限制. 发现一篇老外的文章,动态设置filt ...
- (转)在ASP.NET MVC3 中利用Jsonp跨域访问
原文地址:http://www.cnblogs.com/skm-blog/p/3431999.html 在信息系统开发的时,根据相关业务逻辑难免会多系统之间互相登录.一般情况下我们需要在多系统之间使用 ...
- 在ASP.NET MVC3 中利用JSONP跨域登录WEB系统
在信息系统开发的时,根据相关业务逻辑难免会多系统之间互相登录.一般情况下我们需要在多系统之间使用多个用户名和密码.这样客户就需要在多个系统之间重复登陆.每次登录都需要输入用户名和密码.最近比较流行的就 ...
- Asp.net MVC3中全局图片防盗链
怎么样在Asp.Net MVC3中做到全局图片防盗链?如果熟悉Asp.Net的页面生命周期,相信解决这个问题应该很容易.下面就演示一下如何去做? 一.首先是全局的,我们肯定要在Global.asax文 ...
- 在Asp.net MVC中应该怎样使用Spring.Net
简单工厂 专门定义一个类来负责创建其他类的实例,被创建的实例通常都具有共同的父类或接口.简单工厂模式又称为静态工厂方法(Static Factory Method)模式,属于类的创建型模式,通常根据一 ...
- jQuery Uploadify在ASP.NET MVC3中的使用
1.Uploadify简介 Uploadify是基于jQuery的一种上传插件,支持多文件.带进度条显示上传,在项目开发中常被使用. Uploadify官方网址:http://www.uploadif ...
随机推荐
- LeetCode 409 Longest Palindrome
Problem: Given a string which consists of lowercase or uppercase letters, find the length of the lon ...
- java实现批量上传(swfupload)
下载 swfupload 文件夹 里面包含handlers.js,swfupload.js,swfupload.swf 三个文件. 我的是和ssh项目整合在一起的.因为struts2的拦截器会拦截所有 ...
- centOS目录结构
rpm包到 /usr/bin/dirName 二进制包(需要解压 -> 生成配置文件 -> make(编译) -> 安装)放到 /usr/local/src/** mongodb ...
- 警告 - no rule to process file 'WRP_CollectionView/README.md' of type net.daringfireball.markdown for architecture i386
warning: no rule to process file '/Users/mac/Downloads/Demo/Self/WRP_CollectionView/WRP_CollectionVi ...
- windows重新获取IP
win+r------->cmd------>ipconfig /release (释放ip) ipconfig /renew 重新获取ip
- 自动复制转换StringBuffer
自动复制转换StringBuffer http://www.cnblogs.com/coqn/archive/2012/07/31/all_StringBuufer.html http://blog. ...
- 微信支付开发(1) JS API支付V3版(转)
http://www.cnblogs.com/txw1958/p/wxpayv3-jsapi.html 本文介绍微信支付下的jsapi实现流程 前言 微信支付现在分为v2版和v3版,2014年9月10 ...
- LightOJ 1030 Discovering Gold(期望 概率)
正推,到达i的概率为p[i],要注意除了1和n外,到达i的概率并不一定为1 概率表达式为p[i] += p[j] / min(n - j, 6) 从j带过来的期望为exp[i] += exp[j] / ...
- phpcms v9网站搬家更换域名的方法
PHPCMS 是国内领先的网站管理系统,同时也是一个开源的PHP开发框架. 本文介绍phpcms v9网站搬家更换域名的方法. 1.在新的主机空间把phpcms安装好. 新安装的版本一定要和准备搬迁的 ...
- hdu 4063 福州赛区网络赛 圆 ****
画几个图后,知道路径点集一定是起点终点加上圆与圆之间的交点,枚举每两个点之间是否能走,能走则连上线,然后求一遍最短路即可 #include<cstdio> #include<cstd ...