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); }
在路由中启用CROSS,说对整个API项目有效...
本文介绍了一种解决跨源资源共享(CORS)问题的方法,通过在ASP.NET Web API项目中安装Microsoft.AspNet.WebApi.Cors包并配置跨域访问,允许所有来源、请求头和方法,确保API能正确响应跨域请求。


3764

被折叠的 条评论
为什么被折叠?



