public void Configure(HttpConfiguration config) { var corsConfig = new WebApiCorsConfiguration(); corsConfig.RegisterGlobal(config); corsConfig .ForAllResources() .ForAllOrigins() .AllowAll(); config.Routes.MapHttpRoute( name: "API Default", routeTemplate: "{controller}/{id}", defaults: new { id = RouteParameter.Optional }); //tell API to use JSON instead of XML config.Formatters.XmlFormatter.SupportedMediaTypes.Remove( config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml")); //var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First(); //jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }
public static void RegisterCors(HttpConfiguration httpConfig) { var corsConfig = new WebApiCorsConfiguration(); // this adds the CorsMessageHandler to the HttpConfiguration’s // MessageHandlers collection corsConfig.RegisterGlobal(httpConfig); // this allow all CORS requests corsConfig.ForAllResources().AllowAllOrigins().AllowAll(); }
public static void RegisterCors(HttpConfiguration httpConfig) { WebApiCorsConfiguration corsConfig = new WebApiCorsConfiguration(); // this adds the CorsMessageHandler to the HttpConfiguration’s // MessageHandlers collection corsConfig.RegisterGlobal(httpConfig); // this allow all CORS requests to the Products controller // from the http://foo.com origin. corsConfig .ForAllResources() .ForAllOrigins() .AllowAll(); }
public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type. // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries. // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712. //config.EnableQuerySupport(); // To disable tracing in your application, please comment out or remove the following line of code // For more information, refer to: http://www.asp.net/web-api config.EnableSystemDiagnosticsTracing(); // Configure Cross-Origin Resource Sharing (CORS) var corsConfig = new WebApiCorsConfiguration(); corsConfig.RegisterGlobal(config); corsConfig .ForAllResources() .ForOrigins( "https://myvote.azurewebsites.net", "http://myvote.azurewebsites.net", "http://myvotelive.com", "https://myvotelive.com", "http://localhost:62043") .AllowAll(); // register JWT authorization validation string zumoMaster = RoleEnvironment.IsAvailable ? CloudConfigurationManager.GetSetting("zumoMaster") : ConfigurationManager.AppSettings["zumoMaster"]; JsonWebTokenValidationHandler.Register(config, zumoMaster); }