Skip to main content

CORS | C#

  • CORS | C#
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Other configuration code...

config.EnableCors();
}
}

/* 2 passo */
// Enable CORS for a specific controller, allowing any origin, any method, and any header
[EnableCors(origins: "*", headers: "*", methods: "*")]
public class ValuesController : ApiController
{
// ...
}

// Enable CORS for a specific action, allowing only specific origins, methods, and headers
[EnableCors(origins: "https://www.example.com", headers: "accept,content-type", methods: "GET,POST")]
public class UsersController : ApiController
{
// ...
}