WebApi的cors(软件包Microsoft.AspNet.WebApi.Cors)似乎未添加标头

时间:2018-07-26 10:49:46

标签: cors asp.net-web-api2

在干净的WebApi项目上(无asp.net核心)

为webapi安装了cors

Install-Package Microsoft.AspNet.WebApi.Cors

添加了此

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // added these to enable cors globally
            var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);


            // Route dell'API Web
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }

在响应中调用任何控件都没有我期望的标头

Access-Control-Allow-Headers: *
Access-Control-Allow-Origin: *
Access-Control-Request-Method: *

0 个答案:

没有答案