Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9001/api/size/get. (Reason: CORS header ...
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項目有效...