asp.net-mvc-3 – _AppStart正在执行时无法创建存储范围

使用ASP.NET MVC 3.0与Visual Studio 2010(SP1之前和SP1)和ASP.NET开发服务器我得到错误“_AppStart正在执行时无法创建存储范围”。每次我调试当我等待几秒钟,并刷新浏览器它按预期工作。

这是否发生在每个人身上?
有没有办法来预防?
我应该在生产中担心吗? (IIS 6/7主机)

相关work-item #7828 on codeplex没有正式的回复

全堆栈跟踪:

Server Error in '/' Application.
--------------------------------------------------------------------------------
Storage scopes cannot be created when _AppStart is executing. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: system.invalidOperationException: Storage scopes cannot be created when _AppStart is executing.

Source Error: 

An unhandled exception was generated during the execution of the current web request. information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 
[InvalidOperationException: Storage scopes cannot be created when _AppStart is executing.]
   System.Web.WebPages.Scope.AspNetRequestScopestorageProvider.set_CurrentScope(IDictionary`2 value) +83361
   System.Web.WebPages.Scope.Scopestorage.CreateTransientScope(IDictionary`2 context) +95
   System.Web.WebPages.Scope.Scopestorage.CreateTransientScope() +76
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +84
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__displayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__displayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__displayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__displayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862381
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously) +184

解决方法

虽然我不知道为什么会发生这种情况(我也不能重现这一点)我可能会有一些修复,你可以尝试。 WebPageHttpModule(在System.Web.WebPages中)应该设置为AppStartExecuteCompleted,但它不会,这就是为什么你得到一个异常(所有这些猜测工作是基于此)。

所以…看看源代码我相信这个bug的根源是Web开发服务器和PreApplicationCode动态注册一个模块(WebPageHttpModule)的东西。模块init应该始终运行在应用程序开始,但由于某种原因我GUESS它没有。也许有人可以以某种方式测试它。

一些我想到的修复(再次,这是纯粹的猜测工作,因为我无法重现)。

1)尝试在WebConfig中静态注册WebPageHttpModule模块。更新我已经测试了这个,这不会抛出异常。但是,它注册了两个httpmodules。

2)根据对你链接的线程的评论,似乎这不会发生在IIS上,所以我试图运行在IIS Express(在VS 2010 SP1下)。

正如我之前所说,这只是猜测工作。模块不能运行可能有其他原因…如Web服务器未正确重新启动,包括PreApplicationCode中的一些问题,或者不将HttpModule中的s_appStartExecutedLock重置为false,或者与HttpContext.Items相关的内容可能还有导致模块不能运行…

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....