对预检请求的响应未通过访问控制检查 .

XMLHttpRequest cannot load http://localhost:49531/Access/Authenticate. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:31775' is therefore not allowed access.

我正在提出请求 OPTIONS . 请求返回代码200,但我仍然收到此错误 .

protected void Application_BeginRequest()
        {
            if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS")
            {
                Response.Flush();
                Response.End();
            }
        }

我想要做的是从客户端和服务器端向 header 添加一个令牌 . 对客户端进行身份验证后,会将令牌添加到服务器的请求中 . 从客户端发起的下一个请求,此令牌由javascript发送 .