Exemplo n.º 1
0
        public static void RegisterCors(HttpConfiguration httpConfig)
        {
            WebApiCorsConfiguration corsConfig = new WebApiCorsConfiguration();

            // this adds the CorsMessageHandler to the HttpConfiguration's
            // MessageHandlers collection
            corsConfig.RegisterGlobal(httpConfig);
            corsConfig
            .ForAllOrigins()
            .AllowAll();
        }
Exemplo n.º 2
0
        private static void ConfigureCors(HttpConfiguration config)
        {
            var corsConfig = new WebApiCorsConfiguration();

            config.MessageHandlers.Add(new CorsMessageHandler(corsConfig, config));

            corsConfig
            .ForAllOrigins()
            .AllowAllMethods()
            .AllowAllRequestHeaders();
        }
Exemplo n.º 3
0
        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();
        }
        //http://brockallen.com/2012/06/28/cors-support-in-webapi-mvc-and-iis-with-thinktecture-identitymodel/
        protected virtual void RegisterCors(HttpConfiguration configuration, string allowedOrigins)
        {
            configuration.MessageHandlers.Add(new R22CorsWebkitHackHandler());
            var corsConfig = new WebApiCorsConfiguration();

            if (allowedOrigins == null)
            {
                corsConfig
                .ForAllOrigins()
                .AllowAllMethods()
                .AllowCookies()
                .AllowRequestHeaders(_allowedRequestHeaders);
            }
            else
            {
                corsConfig
                .ForOrigins(allowedOrigins.Split(','))
                .AllowAllMethods()
                .AllowCookies()
                .AllowRequestHeaders(_allowedRequestHeaders);
            }

            corsConfig.RegisterGlobal(configuration);
        }