在 IIS7 集成模式下获取 NullReferenceException
我有一个运行 .NET 4.0 和
- MVC 3.0
- Microsoft ServiceLocator 1.0
- StructureMap 2.6.2
- StructureMap Adapter 1.1.0.2
- NHibernate 3.1.0.4000
- Log4Net 1.2.10
该应用程序在开发服务器、IIS6 和 IIS7 经典模式下运行良好。 在 IIS7 集成模式下运行同一应用程序会在 Global.asax Application_Start 之后出现 NullReferenceException。
堆栈跟踪是:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.PipelineStepManager.ResumeSteps(Exception error) +1116
System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +89
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +189
附加的调试器不会因异常而中断。但页面显示的是死亡黄页。
知道我可以在哪里查看或挂钩来修复错误吗?
I've an application runing .NET 4.0 with
- MVC 3.0
- Microsoft ServiceLocator 1.0
- StructureMap 2.6.2
- StructureMap Adapter 1.1.0.2
- NHibernate 3.1.0.4000
- Log4Net 1.2.10
The application is running well in development server, IIS6 and IIS7 classic mode.
Running the same application in IIS7 integrated mode gives after Global.asax Application_Start an NullReferenceException.
The stacktrace is:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.PipelineStepManager.ResumeSteps(Exception error) +1116
System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +89
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +189
The attached debugger does not break at exception. But the page shows the yellow page of death.
Any idea where I can look or hook to fix the error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据将 ASP.NET MVC NHibernate 应用程序部署到IIS7 和许多其他posts 如果应用程序运行在集成模式下,则不再支持在 Application_Start 中初始化 NHibernate。我没有找到这种行为的真正原因。可能是Darins的回答是原因,但我发现NHibernate初始化代码中没有访问HttpContext.Current。
解决方法是:
According to Error when deploying ASP.NET MVC NHibernate app to IIS7 and a lot other posts it is not supported to initialized NHibernate in Application_Start anymore if application is running in integrated mode. I found no real reason for that behavior. May be that Darins answer is the reason, but I found no access to HttpContext.Current in NHibernate initialization code.
The workarounds are:
在集成模式下运行时,诸如 HttpContext、Request、Response、Session 等对象在
Application_Start
中不可用。因此,请确保您的代码中没有任何代码尝试在此方法中访问它们。When running in integrated mode, objects such as the HttpContext, Request, Response, Session, ... are not available in
Application_Start
. So make sure none of your code tries to ever access them in this method.