ASP.NET MVC application when deployed to IIS 7 in integrated mode using NHibernate data will not load

跟風遠走 提交于 2019-12-23 03:49:29

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/2074968/asp-net-mvc-application-when-deployed-to-iis-7-in-integrated-mode-using-nhiberna

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!