Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have Uploaded data in cross browser using **AWS instance** sucessfully.But when I am trying to do the same on **windows Azure** I got the following error:

**Cross-Origin Request Blocked: The Same Origin Policy disallows reading the
remote resource. This can be fixed by moving the resource to the same domain
or enabling CORS**

My Post method is given below :

JavaScript
$.ajax({
                type: 'POST',
                crossDomain: true,
                url: 'http://dplannerpython.cloudapp.net:8888/upload',
                data: form_data,
                contentType: false,
                cache: false,
                processData: false,
                async: true,
                success: function (data) {                   
                   
                    alert("Upload Successful! You can run a job once the data is configured");                    
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(thrownError);
                }
            });
Posted
Updated 14-Apr-16 22:52pm

You have not shared your API Code but check below EnableCors() method and if it is not implemented then implement it.


C#
public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.EnableCors();




Thanks
Rushi
 
Share this answer
 
After enabling Cors option please change your web.config as follow.

XML
<system.webServer>
  <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
      </customHeaders>
    </httpProtocol>
 <ModSecurity enabled="false" configFile="C:\inetpub\wwwroot\owasp_crs\modsecurity.conf" />
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
   
  </system.webServer>
 
Share this answer
 

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