Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
CORS request not working in Windows Safari I am making a CORS request to upload a file i am using Plupload plugin to upload a file . This works fine in chrome, however when I run in safari I get an ' Origin http://localhost is not allowed by Access-Control-Allow-Origin.'. I have set the CORS on the server.

This is Request headers

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

What I have tried:

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();
                } 
            //}
        }
Posted
Comments
Prateek Dalbehera 15-Mar-17 3:50am    
in config of server, have you used "*" or restricted to some specific domain?? also, check annotations in the method definition in server side code
surajemo 8-Apr-17 1:35am    
Actually there was no problem in CORS the problem was the browser was not supporting FileReader object i was uploading large files by splitting them in chunks but the browser was not supporting File Reader

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900