Referencing system.web.cors

2019-03-17 14:12发布

问题:

I'm trying to implement cors support in my Web API.

I have read a couple of blog posts on this topic, but I can't seem to find System.Web.Cors.dll or System.Web.Http.Cors.dll

Is there something I need to install?

回答1:

Create a .NET 4.5 MVC project, install nuget package "Microsoft ASP.NET Web API [version] Cross-Origin Support" (search for "cors" and it will be on 1st or 2nd place in list). That's it.

P.S. If you encounter errors try to install "Microsoft ASP.NET Web API [version]" package too (search for "WebApi").



回答2:

The System.Web.Cors assembly is now available on NuGet in the Microsoft.AspNet.Cors package. This is currently a prerelease package, so if you're using the Visual Studio package manager, you'll need to include prerelease packages.



回答3:

The only way to use System.Web.Cors locally is to use the nightly builds as per this discussion. http://aspnetwebstack.codeplex.com/discussions/436442



回答4:

According to this thread, you can get it using nightly builds of ASP.NET using nuget (see instructions here). But it sounds like it is only compatible with v5 of System.Web.Http so you'll potentially need to get that also. That is certainly not RTM so you'd have to be comfortable with that.