0

I have already added the * as the Access-Control-Allow-Origin but the request yields a 404 saying that

No 'Access-Control-Allow-Origin' header is present on the requested resource.

My Controller code:

            [AllowCrossSiteJsonAttribute]
            [HttpPost]
            public JsonResult uploadzip()
            {

                Response.AddHeader("Access-Control-Allow-Origin", "*");       // Need to add the correct domain in here!!
                Response.AddHeader("Access-Control-Allow-Methods", "POST");   // Only allow POST
                Response.AddHeader("Access-Control-Max-Age", "300");          // Cache response for 5 minutes
                Response.AddHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");         // Ensure this header is also allowed!  

                ...

                return Json(json);
             }

I am sure this is the correct way to go.. Is there something missing ?

The post request below:

 $.ajax({
            url: 'http://site1.com/auth/uploadzip',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: 'application/zip',
            success: function (d, t, x) {
                if (d.status == "success") {

                }}});

Even tried the custom attribute way described here.

Still the browser complains:

XMLHttpRequest cannot load http://site1.com/auth/uploadzip. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://site2.com' is therefore not allowed access. The response had HTTP status code 404.

Any more pointers?

Community
  • 1
  • 1
Nezam
  • 4,122
  • 3
  • 32
  • 49
  • 1
    The code you've shown reacts to an HTTP `POST`. But you need to respond to an `OPTIONS` request, first, and specify the access control headers on *that* response in order for the browser to even *perform* the `POST` request. – Damien_The_Unbeliever Sep 15 '15 at 09:01
  • @Nezam Search the site: http://stackoverflow.com/questions/7001846/how-to-handle-options-method-in-asp-net-mvc – Sheepy Sep 15 '15 at 10:31
  • @Sheepy did that already. See the edit. – Nezam Sep 15 '15 at 11:02

0 Answers0