Created
November 23, 2017 11:24
-
-
Save vishnoor/b5cf28cb3ebc452f77896e30a2d6efb2 to your computer and use it in GitHub Desktop.
Line needed to enable CORS in Web API 5.0
This file contains hidden or 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
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