asp.net-mvc 尝试通过安全透明方法 'WebMatrix.WebData.PreApplicationStartCode.Start()'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17926552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:03:10  来源:igfitidea点击:

Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()'

asp.net-mvc

提问by Elger Mensonides

Update: same for mvc 4 to mvc 5.

更新:mvc 4 到 mvc 5 相同。

I started a new mvc 4 project and migrated an mvc 3 project in it (controllers/models/scripts etc). While everything compiles now i get the following error:

我开始了一个新的 mvc 4 项目并在其中迁移了一个 mvc 3 项目(控制器/模型/脚本等)。虽然现在一切都编译了,但我收到以下错误:

Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)' failed.

尝试通过安全透明方法“WebMatrix.WebData.PreApplicationStartCode.Start()”访问安全关键方法“System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)”失败。

I can't find anything on the web with this error. The error hits before getting into the application start.

我在网上找不到任何有关此错误的内容。在进入应用程序启动之前发生错误。

I tried reinstalling all assemblies with nuget, putting a 'clean' web.config to no avail.

我尝试使用 nuget 重新安装所有程序集,但放置“干净”的 web.config 无济于事。

Anyone had this problem before?

以前有人遇到过这个问题吗?

回答by Michael

For me this error was because I did NOT have Microsoft.AspNet.WebHelpers installed after updating from MVC 4 to MVC 5. It was fixed by installing the NuGet package

对我来说,这个错误是因为我在从 MVC 4 更新到 MVC 5 后没有安装 Microsoft.AspNet.WebHelpers。它是通过安装 NuGet 包修复的

Install-Package -Id  Microsoft.AspNet.WebHelpers

回答by Anushka

If you are getting the error

如果您收到错误

Attempt by security transparent method ‘WebMatrix.WebData.PreApplicationStartCode.Start()' to access security critical method ‘System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)' failed.

尝试通过安全透明方法“WebMatrix.WebData.PreApplicationStartCode.Start()”访问安全关键方法“System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)”失败。

In order to fix this install this package using NuGet package manager.

为了解决此问题,请使用 NuGet 包管理器安装此包。

Install-Package Microsoft.AspNet.WebHelpers

After that , probably you will get another error

在那之后,您可能会遇到另一个错误

Cannot load WebMatrix.Data version 3.0.0.0 assembly

无法加载 WebMatrix.Data 3.0.0.0 版程序集

to fix this install this package using NuGet package manager.

要修复此问题,请使用 NuGet 包管理器安装此包。

Install-Package Microsoft.AspNet.WebPages.Data

回答by Alex Dresko

For anyone landing here who is trying to upgrade from MVC 4 to MVC5, I was able to resolve this issue by following the instructions at 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.

对于尝试从 MVC 4 升级到 MVC5 的任何人,我能够按照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

I also had to install the "Microsoft.AspNet.WebApi.WebHost" package from nuget. But that's it.

我还必须从 nuget 安装“Microsoft.AspNet.WebApi.WebHost”包。但就是这样。

Oh, and I had to create this appSetting: <add key="owin:AutomaticAppStartup" value="false" />

哦,我必须创建这个 appSetting: <add key="owin:AutomaticAppStartup" value="false" />

:)

:)

回答by Paul

I tried all of the above solutions and it still wouldn't work, until I found that the web.config compilation element was referencing version 2.0.0.0 of WebMatrix.Data and WebMatrix.WebData. Changing the version of those entries in the web.config to 3.0.0.0 helped me.

我尝试了上述所有解决方案,但仍然无法正常工作,直到我发现 web.config 编译元素引用了 WebMatrix.Data 和 WebMatrix.WebData 的 2.0.0.0 版。将 web.config 中这些条目的版本更改为 3.0.0.0 对我有帮助。

回答by Edward Olamisan

I've been struggling with a similar issue when upgrading mvc 4to mvc 5:

升级mvc 4mvc 5以下时,我一直在努力解决类似的问题:

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()”访问安全关键方法“System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)”失败。

The delete extra files check box in the publish dialog solved it for me.

发布对话框中的删除额外文件复选框为我解决了这个问题。

回答by Pablo Claus

Reinstalling Microsoft.AspNet.WebHelpersworks for me

重新安装Microsoft.AspNet.WebHelpers对我有用

Update-Package –reinstall Microsoft.AspNet.WebHelpers

回答by chris

Just one more suggestion... This was caused for me by some old dll's from an MVC 3 project after upgrading to MVC 5 in the site bin folder on the deployment server. Even though these dll's were no longer used by the code base they appeared to be causing the problem. Cleaned it all out and re-deployed and it was fine.

还有一个建议……这是在部署服务器上的站点 bin 文件夹中升级到 MVC 5 后,来自 MVC 3 项目的一些旧 dll 对我造成的。尽管代码库不再使用这些 dll,但它们似乎是导致问题的原因。把它全部清理干净并重新部署,它很好。

回答by Simon_Weaver

You may also get :

您还可以获得:

Could not load file or assembly 'WebMatrix.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

无法加载文件或程序集“WebMatrix.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)

This has moved to this package

这已经转移到这个包

 Install-Package Microsoft.AspNet.WebPages.Data

You should probably do a clean build before attempting any of the answers to this question and after updating packages

在尝试回答此问题的任何答案之前和更新软件包之后,您可能应该进行干净的构建

回答by Mostafa

Here is how I fixed this issue:

以下是我解决此问题的方法:

Open the nuget package manager consoleand install the below nuget packages:

打开 nuget包管理器控制台并安装以下 nuget 包:

Install-Package WebMatrix.Data
Install-Package Microsoft.AspNet.WebHelpers
Update-Package

Clean the solution, rebuild and my asp.net web app starts working!

清理解决方案,重建,我的 asp.net web 应用程序开始工作!

回答by theskhan

Deleting all files from bin and then rebuilding the solution worked for me.

从 bin 中删除所有文件,然后重建解决方案对我有用。