CORS请求在51.1.7中的Windows Safari版本中不起作用

时间:2017-03-12 19:24:25

标签: javascript asp.net-mvc safari cors

CORS请求在Windows Safari中不起作用 我正在发送一个CORS请求来上传我正在使用Plupload插件上传文件的文件。这适用于铬, 然而,当我在野生动物园里跑步时,我会得到一个' Access-Control-Allow-Origin不允许原点http://localhost。'。   我在服务器上设置了CORS。

 protected void Application_BeginRequest(object sender, EventArgs e)
        {
            try
            {
               EnableCrossDomainAjaxCall();
            }
            catch (Exception ex)
            { 
                ErrorHandlerTools.LogError(ex);
            }
        }
 private void EnableCrossDomainAjaxCall()
        { 
           // if (ValidateRequest())
          //  {
                HttpContext.Current.Response.Headers.Remove("Access-Control-Allow-Origin");
                Response.AddHeader("Access-Control-Allow-Origin", "*");

                if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
                {
                    HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.OK;
                    HttpContext.Current.Response.Headers.Remove("Access-Control-Allow-Methods");
                    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "HEAD, GET, PUT, POST, COPY, OPTIONS, DELETE");

                    HttpContext.Current.Response.Headers.Remove("Access-Control-Allow-Credentials");
                    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true");

                    HttpContext.Current.Response.Headers.Remove("Access-Control-Allow-Headers");
                    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "origin,x-requested-with,content-Type,accept,x-auth-token,x-custom-header");

                    HttpContext.Current.Response.Headers.Remove("Access-Control-Max-Age");
                    HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");

                    HttpContext.Current.Response.End();
                } 
            //}
        }

这是请求标头

Origin: http://localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryLUZFR1paN3ARVMRv
Referer: http://localhost/PetaTracker/UploadView/machineView/LargeFile

任何人都可以让我知道我哪里出错了 你会很善良的。

1 个答案:

答案 0 :(得分:0)

尝试添加

<AllowedHeader>origin</AllowedHeader>

在配置中。