C# – Enable CORS in Web API 2

Lets enable CORS in Web API 2

Use Nuget,

Step (1).

Go to: TOOLS > Library Package Manager > Package Manager Console, and type in:

Install-Package Microsoft.AspNet.WebApi.Cors

Step (2).

Add these line in WebApiConfig.cs file which is inside App_Start folder

public static void Register(HttpConfiguration config)
{
    //enable cores
    var enableCorsAttribute = new EnableCorsAttribute("*","Origin, Content-Type, Accept","GET, PUT, POST, DELETE, OPTIONS");
    config.EnableCors(enableCorsAttribute);
}

And ya thats all its done.

Author Profile

PREM KUMAR
PREM KUMAR
Tech Lover , Open Src Dev , Dotnet Core, Ionic, Xamarin, Node, Angular2, Python, Opencv, AI, ML, Robotics, SignalR, Iot, Love Music, Cooking, Girls, Innovation.
Like
Like Love Haha Wow Sad Angry

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enable Notifications.    Ok No thanks