Search code examples
asp.netvisual-studiosecuritysame-origin-policy

Same Origin Policy with 2 projects on separate ports


I have 2 web applications running on 2 separate ports: localhost:35000 and localhost:35001, each mapping to mySite.com and api.mySite.com respectively. Now because they are both running on separate ports, this triggers the same origin policy which prevents me from using javascript to call to the api.

Is there a way around this? Whether it is setting up visual studio to have both applications running on the same port or allowing some cross domain thing across ports for localhost.


Solution

  • The port is not crucial in this case; it's rather the different domain names that the client see.

    Implementiert the Cross Origin Resource Sharing protocol on your API server. It allows cross origin XHR requests while giving the server the authority to control which request from which origin is allowed.