Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between AspNet.Cors and AspNet.WebApi.Cors?

In my application I have the following two nuget packages installed:

  • Microsoft.AspNet.Cors - 5.2.2
  • Microsoft.AspNet.WebApi.Cors - 5.2.2

My application is a WebAPI back-end connected to an AngularJS front-end. The back-end and front-end are on different web servers. The application uses bearer authentication and logon is estabilished with a call to /token. I am using ASP.Net Identity 2.1

I have managed to get CORS working by following directions from here:

http://www.codeproject.com/Articles/742532/Using-Web-API-Individual-User-Account-plus-CORS-En

However I would like to learn more about the differences between the two Cors packages. Are they both required for my type of project and when would one use the AspNet.Cors and when would one use the WebApi.Cors?

like image 477
Samantha J T Star Avatar asked Dec 06 '14 12:12

Samantha J T Star


People also ask

What is CORS in Web API?

Cross-origin resource sharing (CORS) is a browser security feature that restricts cross-origin HTTP requests that are initiated from scripts running in the browser. If your REST API's resources receive non-simple cross-origin HTTP requests, you need to enable CORS support.


1 Answers

  1. Microsoft.AspNet.WebApi.Cors: use it to enable the CORS request ONLY for the Web APIs.

  2. Microsoft.AspNet.Cors: I think you can use this when you want to enable CORS for your MVC controllers.

  3. Microsoft.Owin.Cors: use it to enable CORS for all cross-origins requests coming to your site, so if you use Web API and SignalR for example and you want to enable CORS for both- use Microsoft.Owin.Cors library.

Hope that helps.

like image 75
Omar.Alani Avatar answered Oct 13 '22 13:10

Omar.Alani