Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing system.web.cors

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?

like image 948
Null Reference Avatar asked Apr 03 '13 03:04

Null Reference


People also ask

What is System Web CORS?

This class defines an attribute that can be applied to an action or a controller to enable CORS. By default, it allows all origins, methods and headers. Namespace: System.Web.Http.Cors.

Why use CORS in Web API?

CORS is a W3C standard that allows you to get away from the same origin policy adopted by the browsers to restrict access from one domain to resources belonging to another domain. You can enable CORS for your Web API using the respective Web API package (depending on the version of Web API in use) or OWIN middleware.


2 Answers

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").

like image 52
Petr Abdulin Avatar answered Oct 01 '22 01:10

Petr Abdulin


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.

like image 42
Jaecen Avatar answered Oct 01 '22 01:10

Jaecen