Skip to content

Instantly share code, notes, and snippets.

@jayhjkwon
Last active December 24, 2015 23:09
Show Gist options
  • Save jayhjkwon/6878275 to your computer and use it in GitHub Desktop.
Save jayhjkwon/6878275 to your computer and use it in GitHub Desktop.
CORS support in ASP.NET WebAPI2
Install-Package Microsoft.AspNet.WebApi.Cors -pre -project WebService
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Cors;
namespace WebService.Controllers
{
[EnableCors(origins: "http://myclient.azurewebsites.net", headers: "*", methods: "*")]
public class TestController : ApiController
{
// Controller methods not shown...
}
}
using System.Web.Http;
namespace WebService
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// New code
config.EnableCors();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment