加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular – > Web Api 2:“没有’Access-Contr

发布时间:2020-12-17 07:00:52 所属栏目:安全 来源:网络整理
导读:基本上我正在尝试访问上传到Azure上的web api. 我已将我的CORS属性添加到我的WebApiConfig类: public static void Register(HttpConfiguration config){ var cors = new EnableCorsAttribute("http://localhost:51407","*","*"); config.EnableCors(cors);
基本上我正在尝试访问上传到Azure上的web api.

我已将我的CORS属性添加到我的WebApiConfig类:

public static void Register(HttpConfiguration config)
{
    var cors = new EnableCorsAttribute("http://localhost:51407","*","*");
    config.EnableCors(cors);

但是每当我发送一个正确包含的Ajax请求(使用angularJS)时

Origin: http://localhost:51407

我收到错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:51407' is therefore not allowed access.

可能是什么问题?

解决方法

对于.NET服务器,可以在web.config中进行配置,如下所示

<system.webServer>
   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="your_clientWebUrl" />
     </customHeaders>
   </httpProtocol>
 </system.webServer>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读