IIS hijacks CORS Preflight OPTIONS request

后端 未结 12 1174
说谎
说谎 2020-11-27 03:57

I am making a CORS POST request and setting the Content-Type header to json. This triggers a Preflight OPTIONS request to fire (this is good and expected)

This OPTIO

12条回答
  •  青春惊慌失措
    2020-11-27 04:27

    In my case, I missed the Microsoft.WebApi.Cors package. Installed this package and configured it like so in the WebApiConfig class:

     public static void Register(HttpConfiguration config)
            {
                config.MapHttpAttributeRoutes();
                config.EnableCors(new EnableCorsAttribute("*","*","*"));
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{id}",
                    defaults: new { id = RouteParameter.Optional }
                );
            }
    

    Please fine-tune this before using in production because you probably don't want to have wild-cards for everything

提交回复
热议问题