qq_28004989
金羽痕
2018-04-16 01:54
采纳率: 51.9%
浏览 1.3k

.net浏览器跨域问题,出现错误

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

这种问题怎么解决?网上都说在页面添加 Response.AddHeader("Access-Control-Allow-Origin",“* ")
添加到哪?在代码里也找不到 Access-Control-Allow-Origin
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • q447552640
    三阶魔方 2018-04-16 01:56
    已采纳

    context.Response.ClearHeaders();
    context.Response.AppendHeader("Access-Control-Allow-Origin","*");
    string requestHeaders = context.Request.Headers["Access-Control-Request-Headers"];
    context.Response.AppendHeader("Access-Control-Allow-Headers",
    string.IsNullOrEmpty(requestHeaders) ? "*" : requestHeaders);
    context.Response.AppendHeader("Access-Control-Allow-Methods", "POST, OPTIONS");

    点赞 评论
  • sm1525362000
    sm1525362000 2018-04-16 03:30

    context.Response.ClearHeaders();
    context.Response.AppendHeader("Access-Control-Allow-Origin","*");
    string requestHeaders = context.Request.Headers["Access-Control-Request-Headers"];
    context.Response.AppendHeader("Access-Control-Allow-Headers",
    string.IsNullOrEmpty(requestHeaders) ? "*" : requestHeaders);
    context.Response.AppendHeader("Access-Control-Allow-Methods", "POST, OPTIONS");

    点赞 评论

相关推荐