Search code examples
ajaxvisual-studio-lightswitch

Lightswitch, AJAX and Access-Control-Allow-Origin


I am preparing to demo Lightswitch to a group of about 100 software developers in a couple weeks and have run into a snag.

I have a VS2012 solution with two projects:

  • Lightswitch - simple data model and ApplicationData.svc
  • Web - contains a web page that attempts to communicate with the ApplicationData.svc using JQuery Ajax

My problem is when I try to run the solution and execute the AJAX command, I get the following error:

XMLHttpRequest cannot load http://localhost:37650/ApplicationData.svc/MyEntities.  Origin
http://localhost:53408 is not allowed by Access-Control-Allow-Origin.

After googling around for a while, I found this advice, which looked promising:

<system.webServer> 
  <httpProtocol>
    <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*" />
    </customHeaders>
  </httpProtocol>
</system.webServer> 

But it did not resolve the issue. Any ideas?

Thanks!


Solution

  • I've been running into the same issue, only mine is that I am creating a HTML5 JQuery Mobile application that is NOT a web application. The app is JQuery based app that I am going to run through PhoneGap. My issue is that when I make the calls from the mobile app, I get the same cross domain issues.

    What browser are you using to test? I am doing Chrome and I get the issue because of the initial Options request (see http://www.w3.org/TR/cors/ ). I've tried a bunch of possible solutions, like updating config files and so on, but to no avail.

    My next kick at the cat will be to intercept the initial Options request by creating an IHttpHandler that I can apply as an attribute to the WCF service I am using (did I mention that I created custom WCF services within the Server project in the LightSwitch solution?).

    I'll keep you posted...

    Paul