SEC7123:请求标头密钥不存在于访问控制允许标头列表中



我正在尝试将自定义标头从角度HTTP拦截器传递给我的Web API。我已经在web.config的允许标题列表中添加了标题作为

 <add name="Access-Control-Allow-Origin" value="*" />
 <add name="Access-Control-Allow-Headers" value="Key,Content-Type" />
 <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />

这在 Chome 中工作正常,但在边缘Microsoft它给了我以下错误:

SEC7123: Request header Key was not present in the Access-Control-Allow-Headers list.

我是否缺少其他设置?

我能够通过在 Global.asax 文件的 BeginRequest 方法中添加以下代码来解决这个问题

protected void Application_BeginRequest (Object sender, EventArgs e) 
{
    if (Request.Headers.AllKeys.Contains ("Origin") && Request.HttpMethod == "OPTIONS") 
    {
        Context.Response.AddHeader ("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Key, Accept,Authorization,serverName");
        Context.Response.AddHeader ("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
        Context.Response.End ();
    }
}

相关内容

最新更新