【发布时间】:2014-09-10 21:16:58
【问题描述】:
使用 Visual Studio 2013,我将混合 Asp.Net Webforms/MVC 3/Framework 4.0 Web 应用程序迁移到 Asp.Net Webforms/MVC 5.2.2/Framework 4.5.1。
我按照这些链接中列出的步骤进行操作:
当我在 Visual Studio 中运行应用程序时,出现此错误:
通过安全透明方法尝试 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' 访问安全关键方法 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' 失败。
我已经尝试了我在 StackOverflow 上找到的这些建议,但没有一个能解决问题:
- 清除 bin 文件夹并重建
- 安装 Nuget 包 Microsoft.Aspnet.WebHelpers。
- 确保 System.Web.Mvc 和 System.Web.WebPages 的所有 web.config 引用都指向正确的版本(分别为 5.2.2.0 和 3.0.0.0)。
任何关于如何找到此错误原因的建议将不胜感激。
错误的完整堆栈跟踪:
[MethodAccessException: Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed.]
System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule() +96
System.Web.WebPages.Administration.PreApplicationStartCode.Start() +41
[InvalidOperationException: The pre-application start initialization method Start on type System.Web.WebPages.Administration.PreApplicationStartCode threw an exception with the following error message: Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +559
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.WebPages.Administration.PreApplicationStartCode threw an exception with the following error message: Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9913572
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
【问题讨论】:
-
你试过安装 Microsoft.AspNet.WebPages.Data 包吗?
-
是的,Microsoft.AspNet.WebPages.Data 包已安装。
标签: c# asp.net-mvc asp.net-mvc-5