代码改变世界

跨域405(Method Not Allowed)问题

2018-05-14 09:23 stoneniqiu 阅读(...) 评论(...) 编辑 收藏

zepot post没有问题,用plupload上传出现了这个错误,options过不去。显示Response for preflight has invalid http status code 405

在global中处理下option

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

另外,还要注意header的设定。多个允许的自定义header逗号隔开。不然也会被拒绝。

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