Last active
August 29, 2015 14:13
-
-
Save adhamankar/c145e57f0c2be4a0a471 to your computer and use it in GitHub Desktop.
WebApi and AngularJS CORS setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.config(['$httpProvider', function ($httpProvider) { | |
$httpProvider.defaults.useXDomain = true; | |
delete $httpProvider.defaults.headers.common['X-Requested-With']; | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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