首页 > 数据库技术 > 详细

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).

时间:2016-07-13 20:27:10      阅读:1920      评论:0      收藏:0      [点我收藏+]

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项目有效...

 

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).

原文:http://www.cnblogs.com/insus/p/5666333.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!