Skip to content

Instantly share code, notes, and snippets.

@vishnoor
Created November 23, 2017 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishnoor/b5cf28cb3ebc452f77896e30a2d6efb2 to your computer and use it in GitHub Desktop.
Save vishnoor/b5cf28cb3ebc452f77896e30a2d6efb2 to your computer and use it in GitHub Desktop.
Line needed to enable CORS in Web API 5.0
public static class WebApiConfig {
public static void Register(HttpConfiguration config) {
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.Formatters.XmlFormatter.SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue("multipart/form-data"); config.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new {
id = RouteParameter.Optional
};
//Needed for CORS
EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*"; config.EnableCors(cors);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment