通过'System.Web.Mvc.PreApplicationStartCode.Start()'尝试到关键方法' system . web . webpage . razor.preapplicationstartcode . start()'失败

[英]Attempt by 'System.Web.Mvc.PreApplicationStartCode.Start()' to critical method 'System.Web.WebPages.Razor.PreApplicationStartCode.Start()' failed


My application was working fine and after I did some upgrades I am getting this error.

我的应用程序运行良好,在我做了一些升级之后,我得到了这个错误。

Server Error in '/' Application.


Attempt by security transparent method 'System.Web.Mvc.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.PreApplicationStartCode.Start()' failed. 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.

尝试通过安全透明的方法'System.Web.Mvc.PreApplicationStartCode.Start()'来访问安全关键方法' system . web.razor.preapplicationstartcode . start ()' failed。描述:在执行当前web请求期间发生了一个未处理的异常。请查看堆栈跟踪,了解关于错误的更多信息,以及它源自代码的地方。

Exception Details: System.MethodAccessException: Attempt by security transparent method 'System.Web.Mvc.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.PreApplicationStartCode.Start()' failed.

异常详细信息:系统。方法:通过安全透明方法的System.Web.Mvc.PreApplicationStartCode.Start()访问安全关键方法的system . web.webpage . razor.preapplicationstartcode . start()失败。

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.

源错误:在当前web请求执行期间生成未处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪进行标识。

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18055

版本信息:Microsoft .NET Framework版本:4.0.30319;ASP。净版:4.0.30319.18055

I cannot remember the updates I did. Is there a way to fix this?

我记不得我所做的更新。有办法解决这个问题吗?

14 个解决方案

#1


66  

I think the issue has been solved, but if not, use this package from Nuget:

我认为这个问题已经解决了,但如果不是,用Nuget的这个包:

Install-Package Microsoft.AspNet.Mvc -Version 5.0.0

I have wasted a day for this error but this single line has done the work for me

我为这个错误浪费了一天的时间,但是这一行已经完成了我的工作

#2


13  

tried . . . Install-Package Microsoft.AspNet.Mvc -Version 5.0.0

尝试。安装包Microsoft.AspNet。Mvc - version 5.0.0

and. . . Install-Package -Id Microsoft.AspNet.WebHelpers

和。安装包id Microsoft.AspNet.WebHelpers

both with no success, finally had to update all packages via nuget. . worked!!

两者都没有成功,最终不得不通过nuget更新所有的包。工作! !

http://www.3dbuzz.com/forum/threads/202082-ASP-net-MVC-Error-before-application-start

http://www.3dbuzz.com/forum/threads/202082-ASP-net-MVC-Error-before-application-start

If you're using visual studio open the nuget packages windows and run Update-Package, this will update all your dll to the last version. If it still not work, see this page: http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

如果您正在使用visual studio打开nuget包窗口并运行update - package,这将把您的所有dll更新到最后一个版本。如果它仍然不工作,请参见此页:http://www.asp.net/mvc/tutorials/mvc/mvc/mvc/mvc -4和web-api- 5和web-api-2。

#3


6  

I got this error when deploying a site where Mvc had been upgraded from 4 to 5 but I had not updated web.config.

我在部署Mvc从4升级到5的站点时犯了这个错误,但是我没有更新web.config。

Changing from this:

从这个改变:

<dependentAssembly>
  <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

to this:

:

<dependentAssembly>
  <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>

solved the problem for me.

帮我解决了这个问题。

#4


5  

Managed to solve the issue by following this link: http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

通过以下链接解决了这个问题:http://www.asp.net/mvc/tutorials/mvc-5 how- upgrade-an-aspnet-mvc-4和web-api-project-to-aspnet-mvc-5和web-api-2

#5


5  

For me also same error occured. It was fixed by installing the NuGet package

对我来说也发生了同样的错误。它是通过安装NuGet包来修复的

  Install-Package -Id  Microsoft.AspNet.WebHelpers

#6


4  

I had a similar problem, and solved it by based on the article Updating Razor 2.0 to 3.0 with Asp.net MVC by by Anthony Fassett

我遇到了一个类似的问题,并根据安东尼·法塞特(Anthony Fassett)的文章更新Razor 2.0到3.0的Asp.net MVC,解决了这个问题。

The following block of code was missing from my Web.Config:

我的Web.Config缺少以下代码块:

<dependentAssembly>
  <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>

#7


1  

There are multiple solutions for this problem:

这个问题有多种解决方案:

  • Follow the tutorial on upgrading your asp.net solution
  • 按照本教程来升级asp.net解决方案
  • Don't forget to remove the Microsoft-Web-Helpers dll and install the nuget package Microsoft.AspNet.WebHelpers
  • 不要忘记删除microsoft - web - helper dll并安装nuget包microsoft.aspnet . webhelper

Then, make sure you have upgraded all your nuget Packages (use "Upgrade-Package") and check your dll's in web.config.

然后,确保升级了所有nuget包(使用“升级包”),并在web.config中检查dll。

The error is probably an action in an old DLL, when you are converting your project.

在转换项目时,错误可能是旧DLL中的一个操作。

#8


1  

In my case, a nuget installation had changed my Web.Config:

在我的例子中,nuget安装改变了我的Web.Config:

    <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="1.1.0.0" />
  </dependentAssembly>

newVersion="1.1.0.0"** should be newVersion="5.1.0.0"

新版本= " 1.1.0.0 " * *应该是新版本=“5.1.0.0”

#9


1  

Right Click to Project -> Manage Nuget Packages for solution than find

右键单击Project ->管理解决方案的Nuget包

Microsoft.AspNet.Mvc and Microsoft.Net.Compilers update latest versions

Microsoft.AspNet。Mvc和Microsoft.Net。编译器更新最新版本

#10


1  

In my case it was an incompatibility issue. I had theses pacakges:

在我看来,这是一个不相容的问题。我有这些包:

  • Microsoft.AspNet.Mvc version 4.x
  • Microsoft.AspNet。Mvc版本4. x
  • Microsoft.AspNet.Razor and Microsoft.AspNet.WebPages, version 3.x
  • Microsoft.AspNet。剃刀和Microsoft.AspNet。网页,版本3. x

I suppose that upgrading Mvc to 5.x would have worked, but I needed to keep Mvc 4.x, so i had to downgrade Razor and Mvc to 2.x. To do so, you just have to install the older version, like this:

我想把Mvc升级到5。x可以工作,但是我需要保持Mvc 4。所以我不得不将Razor和Mvc降级为2。x。为此,您只需安装旧版本,如下所示:

Install-package Microsoft.AspNet.WebPages -version 2.0.30506
Install-Package Microsoft.AspNet.Razor -Version 2.0.30506

After downgrading these packages, the first error disappeared, but there was still another error related to a problem in web.config. I had to change the binding redirect for Razor:

在降级这些包之后,第一个错误消失了,但是还有一个错误与web.config中的问题有关。我必须为Razor更改绑定重定向:

<dependentAssembly>
     <assemblyIdentity name="System.Web.Razor" ... />
  <!--bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /-->
     <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>

I don't know why, but the binding redirect wasn't updated by the Nuget installation, which should have done it.

我不知道为什么,但是绑定重定向不是由Nuget安装更新的,应该是Nuget安装更新的。

#11


1  

I solved my problem by applying the "Install-Package Microsoft.AspNet.Mvc" command.

我通过应用“安装包Microsoft.AspNet”解决了我的问题。Mvc”命令。

After that I solved my project with Web API.

之后我用Web API解决了我的项目。

#12


0  

I received this error when I upgraded a NuGet package - 'Microsoft.AspNet.Web Pages' version 3.2.3. I am using VS2012, starting a new vanilla 'ASP.NET MVC 4 Web Application' with template 'Internet Application' using Windows Authentication or Windows Azure authentication.

当我升级了一个名为“Microsoft.AspNet”的NuGet包时,我收到了这个错误。3.2.3网页的版本。我正在使用VS2012,开始一种新的香草“ASP”。NET MVC 4 Web应用程序使用模板“Internet应用程序”使用Windows身份验证或Windows Azure身份验证。

Perhaps the update is not compatible with other components, and these other components must also be upgraded. Other answers suggest updating Microsoft.AspNet.Mvc, Microsoft.Net.Compilers, and/or Microsoft.AspNet.WebHelpers.

更新可能与其他组件不兼容,这些其他组件也必须进行升级。其他的回答建议更新微软。aspnet。Mvc,Microsoft.Net。编译器、和/或Microsoft.AspNet.WebHelpers。

#13


0  

I am working on ASP.NET Web API project and fetch same problem after adding following nuget CacheCow.Server.EntityTagStore.SqlServer

我正在做ASP。NET Web API项目,并在添加了nuget CacheCow.Server.EntityTagStore.SqlServer之后获取相同的问题

It solved installing this one

它解决了安装这个问题。

Install-Package Microsoft.AspNet.Mvc

#14


0  

Install-Package -Id Microsoft.AspNet.WebHelpers

安装包id Microsoft.AspNet.WebHelpers

Install-Package Microsoft.AspNet.Mvc -Version 5.0.0

安装包Microsoft.AspNet。Mvc - version 5.0.0

This worked for me

这为我工作


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2013/11/13/7df42f3570a0e641ae13f9ef0cd9b09c.html



MVC4升级到MVC5的问题,安全透明方法“WebMatrix.WebData.PreApplicationStartCode.Start()”尝试访问安全关键方法“System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)”失败 asp.mvc4升级到asp.mvc5的问题,安全透明方法“WebMatrix.WebData.PreApplicationStartCode.Start()”尝试访问安全关键方法“System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)”失败 尝试通过安全透明方法访问安全关键方法失败 - Attempt by security transparent method to access security critical method failed 尝试使用安全透明方法'WebMatrix.WebData.PreApplicationStartCode.Start()' - Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()' ASP.NET MVC3升级 - “尝试按方法[无论如何]访问方法System.Web.Mvc.Controller.View(...)失败” - ASP.NET MVC3 upgrade - “Attempt by method [whatever] to access method System.Web.Mvc.Controller.View(…) failed” System.MethodAccessException:尝试通过安全透明方法访问安全性关键方法在所有应用程序上失败 - System.MethodAccessException: Attempt by security transparent method to access security critical method fails on all applications 尝试通过方法'System.Web.Helpers.Json.Decode(System.String)'访问字段'System.Web.Helpers.Json._serializer'失败 - Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed 采用安全透明方法X访问安全关键方法Y失败。 - Attempt by security transparent method X to access security critical method Y failed [一]System.Web.WebPages.Razor.Configuration。不能将HostSection转换为[B] system . web . webpage . razor. configuration .HostSection。 - [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection mvc类型的表达式。MvcWebRazorHostFactory'不能用于返回类型' system . web . webpage . razor.webrazorhostfactory ' - The expression of type 'System.Web.Mvc.MvcWebRazorHostFactory' can not be used for return type 'System.Web.WebPages.Razor.WebRazorHostFactory'
 
粤ICP备14056181号  © 2014-2019 ITdaan.com

赞助商广告