ASP.NET MVC应用程序部署到IIS 7时,在集成模式下使用NHibernate数据将不会加载 [英] ASP.NET MVC application when deployed to IIS 7 in integrated mode using NHibernate data will not load

查看:256
本文介绍了ASP.NET MVC应用程序部署到IIS 7时,在集成模式下使用NHibernate数据将不会加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经构建了一个ASP.NET MVC应用程序,它使用 NHibernate MVCContrib 版本的 StructureMap ,以及洋葱结构 Jeffery Palermo在 ASP.NET MVC in Action 中。此应用程序在Visual Studio 2008本地运行时运行良好。



我们的首页控制器上的索引操作载入使用上述工具立即从数据库中提取数据的视图。在IIS 6上运行或在IIS 7上的经典模式下,此部分页面加载数据。当然,在这两种模式中, 404文件未找到错误很多。不幸的是,当在IIS 7集成模式下运行时,无数据加载和简单的错误消息对不起,处理您的请求时出现错误显示在哪里应该呈现数据。其他页面元素如CSS和图像被加载。有没有我们错过的IIS 7设置?有没有什么我应该在web.config中寻找?



修改



将web.config中的 customErrors模式设置更改为 off 。不知道这是否是一个ASP.NET MVC或IIS 7的东西,但是现在看到一个标准错误屏幕在用于显示对不起的错误消息的页面上。我正在收到一个未处理的例外: NullReferenceException :对象引用未设置为对象的实例。看到堆栈,这似乎是在尝试获取数据时发生的。 IIS 7 Classic Mode / IIS 6与IIS 7集成模式之间的区别将会导致此问题?



编辑2



今天早上的一些Google搜索结果发生了一个帖子 MVC + Sharp + IIS7 + NHibernate ,这似乎会解决问题。这个帖子是从09年6月起,在那以后的时候有什么改变,我不需要退缩到经典模式?

解决方案

在考虑了发生了什么后,意识到这个问题可能与NHibernate有关,我改进了我的一些Google搜索,并发现了一个帖子 IIS 7 web.config文件中的HttpModule和HttpHandler部分。这提醒我,NHibernate需要一个 httpModules 条目。

 <系统名.web> 
< httpModules>
< add name =StartupModuletype =Infrastructure.NHibernateModule,
Infrastructure,Version = 1.0.0.0,Culture = neutral/>
< / httpModules>
< /system.web>

由于集成模式下IIS 7的工作方式,我不得不将以下内容添加到< system.webServer>
< validation validateIntegratedModeConfiguration =false/>
< modules runAllManagedModulesForAllRequests =true>
< add name =StartupModuletype =Infrastructure.NHibernateModule,
Infrastructure,Version = 1.0.0.0,Culture = neutral/>
< / modules>
< /system.webServer>

因为我需要两个模块都可以在 system.web system.webServer 我将验证部分添加到系统.webServer


We have built an ASP.NET MVC application which utilizes NHibernate, the MVCContrib version of StructureMap, and an onion architecture as outlined by Jeffery Palermo in ASP.NET MVC in Action. This application works well when running locally from Visual Studio 2008.

The Index action on our Home controller loads a view which immediately pulls data from the database utilizing the tools as outlined above. When running on IIS 6 or in Classic Mode on IIS 7 this section of the page loads data. Of course in both of these modes 404 File Not Found errors abound. Unfortunately, when running under IIS 7 Integrated mode no data loads and a simple error message Sorry, an error occurred while processing your request is displayed where the data should be rendered. Other page elements like CSS and images are loaded. Is there an IIS 7 setting we have missed? Is there something I should be looking for in the web.config?

Edit

Changed the customErrors mode setting in the web.config to off. Not sure if this is an ASP.NET MVC or IIS 7 thing but am now seeing a standard error screen on the pages that used to display the sorry error message. I am getting an unhandled exception of NullReferenceException: Object reference not set to an instance of an object. Looking at the stack this appears to be occurring when trying to get data. What would be the difference between IIS 7 Classic Mode / IIS 6 and IIS 7 Integrated mode that would cause this issue?

Edit 2

After some Googling this morning came across a post MVC + Sharp + IIS7 + NHibernate which seems like it would solve the problem. The post is from June '09 has something changed in the time since then that I don't have to drop back to classic mode?

解决方案

After thinking about what was going on and realizing that issue probably had something to do with NHibernate I refined some of my Google searches and found a post HttpModule and HttpHandler sections in IIS 7 web.config files. This reminded me that NHibernate requires an httpModules entry.

<system.web>
  <httpModules>
    <add name="StartupModule" type="Infrastructure.NHibernateModule,
         Infrastructure, Version=1.0.0.0, Culture=neutral"/>
  </httpModules>
</system.web>

Because of the way that IIS 7 in integrated mode works I had to add the following to the modules section of system.webServer.

<system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="StartupModule" type="Infrastructure.NHibernateModule,
         Infrastructure, Version=1.0.0.0, Culture=neutral" />
  </modules>
</system.webServer>

Because I needed to have both the modules work in both system.web and system.webServer I added the validation section to the system.webServer.

这篇关于ASP.NET MVC应用程序部署到IIS 7时,在集成模式下使用NHibernate数据将不会加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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