且构网

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

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

更新时间:2022-05-20 22:38:02

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

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>