在干净的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: *