2

If I have two Visual Studio projects, one is a WebAPI and the other is a simple web application, I am unable to debug them because I must have CORS enabled. It doesn't matter if the two projects are deployed on the same domain in the future. In order to debug CORS must be enabled. Why is this? They're both debugging on the same workstation, on the same domain, at the same time. Is localhost:port# really seen as two completely different domains? Is there a way to disable this?

Rhendar
  • 410
  • 7
  • 25
  • 1
    If the ports are different, yes, they're seen as different hosting authorities. –  Feb 12 '18 at 18:09
  • ["A user agent makes a cross-origin HTTP request when it requests a resource from a different domain, protocol, **or port** than the one from which the current document originated."](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) –  Feb 12 '18 at 18:10
  • @Amy So it's virtually impossible to have a web api separate from a web application without enabling CORS? At least in terms of debugging. – Rhendar Feb 12 '18 at 18:14
  • If the site is hosted on another port, you must use CORS. –  Feb 12 '18 at 18:14
  • @amy What if CORS doesn't work? I have it set up and it'll let me log in but any time I perform a GET it throws an error. I've tried every possible combination I can find with CORS settings and it just fails every time. https://stackoverflow.com/questions/48750981/mvc-web-api-error-code-script7002 – Rhendar Feb 12 '18 at 18:18
  • If it doesn't work, you need to set it up correctly. It's hard for me to help with that unless you're detailed and specific about how you're trying to set it up. –  Feb 12 '18 at 18:18
  • https://stackoverflow.com/questions/48750981/mvc-web-api-error-code-script7002 Here's a link to my previous question where I posted the code I'm using. – Rhendar Feb 12 '18 at 18:20

1 Answers1

2

@Amy was correct. Localhost:port is seen as a completely different domain. I had to enable CORS in order to debug. For more details see this post:

MVC Web API Error Code SCRIPT7002

Rhendar
  • 410
  • 7
  • 25