gpt4 book ai didi

asp.net-mvc-4 - WebAPI OData 5.0 Beta - 访问 GlobalConfiguration 引发安全错误

转载 作者:行者123 更新时间:2023-12-02 20:34:17 27 4
gpt4 key购买 nike

我最近安装了 WebApi OData 5.0 框架的预发行版本,以体验新的 $expand 支持。一切都构建得很好,但我在 App_Start 上遇到了一个奇怪的异常。

Attempt by security transparent method
'System.Web.Http.GlobalConfiguration.get_Configuration()'
to access security critical type 'System.Web.Http.HttpConfiguration' failed.

来源错误:

Line 12:    protected void Application_Start()
Line 13: {
Line 14: WebApiConfig.Register(GlobalConfiguration.Configuration); // <--
Line 15: }

堆栈跟踪:

[TypeAccessException: Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access 
security critical type 'System.Web.Http.HttpConfiguration' failed.]
System.Web.Http.GlobalConfiguration.get_Configuration() +0
API.WebApiApplication.Application_Start() in Global.asax.cs:14

[HttpException (0x80004005): Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access
security critical type 'System.Web.Http.HttpConfiguration' failed.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12863325
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access
security critical type 'System.Web.Http.HttpConfiguration' failed.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12880068
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12721257

Google 透露的信息很少。

最佳答案

在包管理器控制台中按给定顺序运行以下命令:

Uninstall-Package Microsoft.AspNet.Mvc.FixedDisplayModes
Update-Package Microsoft.AspNet.Mvc -Pre
Update-Package Microsoft.AspNet.WebApi -Pre
Update-Package Microsoft.AspNet.WebApi.Tracing

现在,对 web.config 应用以下更改:

  1. 在项目的 Web.config 中,将应用设置网页:版本的值更新为 3.0.0.0

  2. 在 web.config 的运行时部分下,检查配置的每个程序集的版本并将其更新为添加到项目中的程序集的版本。以下是我的 web.config 中的更新配置:


    < assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

    < assemblyIdentity name="System.Web.Helpers"publicKeyToken="31bf3856ad364e35"/>



    < assemblyIdentity name =“System.Web.Mvc” publicKeyToken =“31bf3856ad364e35”/>



    < assemblyIdentity name =“System.Web.WebPages”publicKeyToken =“31bf3856ad364e35”/>



    < assemblyIdentity name="EntityFramework"publicKeyToken="b77a5c561934e089"/>



    < assemblyIdentity name="WebGrease"publicKeyToken="31bf3856ad364e35"/>



    < assemblyIdentity name= “System.Web.Http”publicKeyToken =“31bf3856ad364e35”文化=“中性”/>



    < assemblyIdentity name =“System.Net.Http.Formatting”publicKeyToken =“31bf3856ad364e35”culture =“neutral”/>



从 Views 文件夹中打开 web.config。这里需要更新三件事:

  1. 在 configSections 下,将 Razor 程序集的版本更新为 3.0.0.0。

  2. 更新 system.web.webPages.razor 部分下的主机版本,将 System.Web.Mvc.MvcWebRazorHostFactory 版本更新为 3.0.0.0。

  3. System.web 的页面部分提到了一些版本号。将它们全部更新到版本5.0.0.0

如果您安装了 Web API 帮助页面,请同时检查上述程序集配置。

关于asp.net-mvc-4 - WebAPI OData 5.0 Beta - 访问 GlobalConfiguration 引发安全错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18347290/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com