加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-4 – WebAPI OData 5.0 Beta – 访问GlobalConfigur

发布时间:2020-12-15 23:24:40 所属栏目:asp.Net 来源:网络整理
导读:我最近安装了WebApi OData 5.0框架的预发布版本,以便使用新的$expand支持.一切都建好了,但是我在App_Start上得到了一个奇怪的例外. Attempt by security transparent method'System.Web.Http.GlobalConfiguration.get_Configuration()' to access security c
我最近安装了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应用以下更改:

>在项目的Web.config中,将应用设置网页值更新为3.0.0.0
>在web.config的运行时段下,检查已组态的每个程序集的版本,并将其更新为添加到项目中的程序集的版本.以下是我的web.config中的更新配置:

<运行时间> < AssemblyBinding xmlns =“urn:schemas-microsoft-com:asm.v1”> < dependentAssembly> < assemblyIdentity name =“System.Web.Helpers”publicKeyToken =“31bf3856ad364e35”/> < bindingRedirect oldVersion =“1.0.0.0-3.0.0.0”newVersion =“3.0.0.0”/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity name =“System.Web.Mvc”publicKeyToken =“31bf3856ad364e35”/> < bindingRedirect oldVersion =“1.0.0.0-5.0.0.0”newVersion =“5.0.0.0”/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity name =“System.Web.WebPages”publicKeyToken =“31bf3856ad364e35”/> < bindingRedirect oldVersion =“1.0.0.0-3.0.0.0”newVersion =“3.0.0.0”/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity name =“EntityFramework”publicKeyToken =“b77a5c561934e089”/> < bindingRedirect oldVersion =“0.0.0.0-5.0.0.0”newVersion =“5.0.0.0”/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity name =“WebGrease”publicKeyToken =“31bf3856ad364e35”/> < bindingRedirect oldVersion =“0.0.0.0-1.3.0.0”newVersion =“1.3.0.0”/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity name =“System.Web.Http”publicKeyToken =“31bf3856ad364e35”culture =“neutral”/> < bindingRedirect oldVersion =“0.0.0.0-5.0.0.0”newVersion =“5.0.0.0”/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity name =“System.Net.Http.Formatting”publicKeyToken =“31bf3856ad364e35”culture =“neutral”/> < bindingRedirect oldVersion =“0.0.0.0-5.0.0.0”newVersion =“5.0.0.0”/> < / dependentAssembly> < / assemblyBinding> < /运行>

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

>在configSections下,将Razor程序集的版本更新为3.0.0.0.
>在system.web.webPages.razor部分更新主机的版本,将System.Web.Mvc.MvcWebRazorHostFactory的版本更新为3.0.0.0.
> System.web的页面部分提到了一些版本号.将它们更新到5.0.0.0版本

如果您安装了Web API帮助页面,请检查以上装配体的配置.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读