Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9001/api/size/get. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
打开API项目录,命名用NuGet安装Microsoft.AspNet.WebApi.Cors:
在WebApiConfig.cs中,添加下面代码:
private static void EnableCrossSiteRequests(HttpConfiguration config)
{
var cors = new EnableCorsAttribute(
origins: "*",
headers: "*",
methods: "*"
);
config.EnableCors(cors);
}
Source Code
在路由中启用CROSS,说对整个API项目有效...