The type initializer for 'System.Web.Http.GlobalConfiguration' threw an exception

前端 未结 3 490
花落未央
花落未央 2021-01-30 12:54

I have added a new Web API project. I install Cors

PM> Install-Package Microsoft.AspNet.WebApi.Cors -Pre

Then when I run my project, I get t

相关标签:
3条回答
  • 2021-01-30 13:02

    I had this problem using NET 4.6.1 and after may hours of research removing this from web.config finally fixed the issue:

    <runtime>
    <dependentAssembly>
         <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
         <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
       </dependentAssembly>
    </runtime>
    
    0 讨论(0)
  • 2021-01-30 13:09

    I had the same problem. Definitely "Cors" doesn't work to me!

    What I did to solve my problem with Cross Domain in WebApi it was remove Cors and change my web.config

    If you insert the following lines inside your web.config, you'll have an WebApi with Cross Domain enabled.

    <system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE" /> </customHeaders> </httpProtocol> </system.webServer>

    0 讨论(0)
  • 2021-01-30 13:11

    I came across the same issue and found a blog post on it. According to this blog post if you use the release candidate it should fix the error

    Install-Package Microsoft.AspNet.WebApi -IncludePrerelease
    

    From here: http://wp.sjkp.dk/webapi-and-cors-enabled-rest-services/

    This worked for me :D

    In other words, it was fixed in 5.1.0-rc1 release.

    0 讨论(0)
提交回复
热议问题