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)
        {
            WebApiCorsConfiguration corsConfig = new WebApiCorsConfiguration();
            corsConfig.RegisterGlobal(httpConfig);

            corsConfig
                .ForResources("Values1")
                .ForOrigins("http://localhost")
                .AllowMethods("GET", "POST");

            corsConfig
                .ForResources("Values2")
                .ForOrigins("http://localhost")
                .AllowMethods("GET", "POST")
                .AllowCookies()
                .AllowResponseHeaders("Foo");

            corsConfig
                .ForResources("Values3")
                .ForOrigins("http://localhost")
                .AllowMethods("GET", "POST", "PUT")
                .AllowRequestHeaders("Content-Type");

            corsConfig
                .ForResources("Values4")
                .ForOrigins("http://localhost")
                .AllowAllMethods()
                .AllowCookies()
                .AllowRequestHeaders("Content-Type", "Foo", "Authorization")
                .AllowResponseHeaders("Foo");
        }
Example #3
0
        public static void RegisterCors(HttpConfiguration httpConfig)
        {
            WebApiCorsConfiguration corsConfig = new WebApiCorsConfiguration();
            corsConfig.RegisterGlobal(httpConfig);

            corsConfig.ForResources("Navigation")
                .ForOrigins("http://localhost:9240")
                .AllowAll();
        }
        //http://brockallen.com/2012/06/28/cors-support-in-webapi-mvc-and-iis-with-thinktecture-identitymodel/
        public static void RegisterCors(HttpConfiguration httpConfig)
        {
            WebApiCorsConfiguration corsConfig = new WebApiCorsConfiguration();
 
            // this adds the CorsMessageHandler to the HttpConfiguration’s
            // MessageHandlers collection
            corsConfig.RegisterGlobal(httpConfig);
       
            corsConfig.AllowAll();
        }
Example #5
0
        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.ForAllOrigins().AllowAll();
        }
    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 to the Products controller

        // from the http://foo.com origin.

        corsConfig.ForResources("RestfulObjects").ForOrigins("http://localhost:49998", "http://localhost:8080").AllowAll().AllowResponseHeaders("Warning");
      
    }
Example #8
0
        public static void RegisterCors(HttpConfiguration httpConfig)
        {
            var corsConfig = new WebApiCorsConfiguration();
            corsConfig.RegisterGlobal(httpConfig);

            var allowedOrigins = WebConfigurationManager.AppSettings.Get("allowedOrigins");

            if (allowedOrigins == null) return;

            var allowedOriginList = allowedOrigins.Split(',');

            if (allowedOriginList.Contains("*"))
            {
                corsConfig.AllowAll();
                return;
            }

            corsConfig.ForOrigins(allowedOriginList).AllowAll();
        }
Example #9
0
    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);
    }
Example #10
0
 public static void RegisterCors(HttpConfiguration httpConfig)
 {
     var corsConfig = new WebApiCorsConfiguration();
     corsConfig.RegisterGlobal(httpConfig);
     corsConfig.AllowAll();
 }
Example #11
0
 public static void RegisterCors(HttpConfiguration httpConfig)
 {
     var corsConfig = new WebApiCorsConfiguration {DefaultCacheDuration = 15000};
     corsConfig.AllowAll();
     corsConfig.RegisterGlobal(httpConfig);
 }