Skip to content

Instantly share code, notes, and snippets.

@adhamankar
Last active August 29, 2015 14:13
Show Gist options
  • Save adhamankar/c145e57f0c2be4a0a471 to your computer and use it in GitHub Desktop.
Save adhamankar/c145e57f0c2be4a0a471 to your computer and use it in GitHub Desktop.
WebApi and AngularJS CORS setup
.config(['$httpProvider', function ($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);
//http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
//Install-Package Microsoft.AspNet.WebApi.Cors
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
config.EnableCors(new EnableCorsAttribute("*", "*", "GET,POST,PUT,DELETE"));
// Web API routes
config.MapHttpAttributeRoutes();
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