码迷,mamicode.com
首页 > 数据库 > 详细

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:28:45      阅读:320      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!