且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CORS 预检通道的 CORS 标头“Access-Control-Allow-Headers"中缺少令牌“access-control-allow-headers"

更新时间:2021-10-16 22:14:20

通常,我读到的帖子建议了几个不必要的配置步骤,这造成了混乱.其实很简单...

Oftentimes, the threads that I read were suggesting several unecessary configuration steps, which created confusion. It's actually very simple...

为了简单的目的,从 Angular 客户端向 ASP 控制器发送跨站点请求:

For the simple purpose of sending a cross site request, from an angular client, to an ASP controller :

  • 不需要角度拦截器.
  • 不需要服务器端的自定义过滤器.
  • 唯一的强制修改是在服务器的 web.config 中添加这个

  • No angular interceptors are required.
  • No custom filters on the server side are required.
  • The only mandatory modification is to add this in the server's web.config

<system.webServer>
      <httpProtocol>
          <customHeaders>
              <clear />
              <add name="Access-Control-Allow-Origin" value="*" />
              <add name="Access-Control-Allow-Headers" value="Content-Type"/>
          </customHeaders>
     </httpProtocol>
</system.webServer>