NHibernate + IIS7.5 抛出“会话工厂已使用 nhibernate.current_session 密钥进行配置”
使用 S#arp Architecture 2.3 RC
,我尝试发布两个主要使用相同代码库的网站。我发布的第一个应用程序运行正确,但是,在部署并尝试运行第二个应用程序时,我收到以下异常:
Access to the path 'C:\Windows\TEMP\nhibernate.current_session--851346262.bin' is denied.
当我刷新窗口时,我收到此异常:
A session factory has already been configured with the key of nhibernate.current_session
我什至尝试将它们加载到单独的应用程序池中并且错误仍然存在。我不明白为什么我的两个应用程序的会话在 IIS 上发生冲突,而它们在 Visual Studio 上运行得很好。
仅供参考,我正在尝试在 Windows Server 2008 R2 + IIS 7.5 上运行它们
有什么帮助吗?
Using S#arp Architecture 2.3 RC
, I am trying to publish two websites which use -mostly- the same codebase. The first of the applications I publish runs correctly, however, upon deploying and trying to run the second application, I get the following exception:
Access to the path 'C:\Windows\TEMP\nhibernate.current_session--851346262.bin' is denied.
When I refresh the window, I then get this exception:
A session factory has already been configured with the key of nhibernate.current_session
I have even tried loading them in separate Application Pools and the error persists. I don't understand how is it that my two applications' sessions are colliding on IIS, whereas they run just fine with Visual Studio.
FYI, I am trying to run them on Windows Server 2008 R2 + IIS 7.5
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通过将应用程序池的身份更改为具有更多权限的身份(例如 LocalSystem)来“修复”它。如果您有权访问源代码,则不是合适的修复方法。
I "fixed" it by changing the application pool's identity to one with more permission e.g. LocalSystem. Not a suitable fix if you have access to the source.
对于使用 #arch 和 NHibernateConfigurationFileCache 的单个网站的情况。问题很可能来自
- NHibernateConfigurationFileCache 使用 Path.GetTempPath() 来保存配置
- 网站使用网络服务或应用程序池标识下的应用程序池运行
- 该身份没有临时路径的写入权限
更好的解决方案是更改代码以使用身份具有权限的临时路径,或者
授予对该身份的临时路径的写入权限(例如,将 c:\windows\temp 上的写入权限授予
IIS APPPOOL\CustomAppPool)
For the case where it is a single website using #arch and NHibernateConfigurationFileCache. The problem most likely comes from
- NHibernateConfigurationFileCache using Path.GetTempPath() to persist the config
- The website is run using application pool under network service or application pool identity
- The identity doesn't have write permission to the temp path
The better solution will be to change the code to use a temp path where the identity will have permission, or
Grant write permission to the temp path for the identity (e.g. grant write permission on c:\windows\temp to
IIS APPPOOL\CustomAppPool)
看起来 S#arp 架构尝试为这两个应用程序使用相同的 NHibernate 会话工厂。它可能会发生冲突,因为当它在磁盘上保留配置时,它对两个 Web 应用程序使用相同的默认“工厂密钥”(nhibernate.current_session)。您应该使用不同的“工厂密钥”吗?为此,您可以阅读有关多个的常见问题解答部分数据库(尽管您没有多个数据库,但您的解决方案可能是相同的):
看看 S#arp sources 我发现他们使用以下逻辑在磁盘上创建文件:
因此,如果您不想更改配置/工厂密钥,您可以尝试从不同的程序集调用此代码。
编辑:
看起来
NHibernateSession.Init
不接受允许您指定工厂密钥的重载。但它还有其他公共方法,您可以调用而不调用 Init:It looks like S#arp Architecture tries to use the same NHibernate session factory for both applications. It maybe colliding because it uses the same default 'factory key' (nhibernate.current_session) for both web apps when it persists configuration on disk. Should you be using different 'factory keys'? In order to do this you can read the FAQ section about multiple databases (although you don't have multiple databases, your solution may be the same):
Looking at S#arp sources I found that they use following logic to create file on disk:
So if you don't want to change config/factory key you can try calling this code from different assembly.
EDIT:
It looks like
NHibernateSession.Init
does not take overload that lets you specify factory key. But it has other public methods that you can call instead of Init: