-2

There is a ASP.NET Core API service site and an ASP.NET Core Angular site on IIS. They are works perfectly. I had to modify a few things in them and I created another two sites with different names and host names to test the modifications. These two also work perfectly. Now I copied the modified sites and I added the host names of the original sites. Naturally I stopped the original sites. Unfortunately the Angular client always throws a CORS error when it wants to reach the srevice site. I know it is a bit complicated but I do not understand it. Maybe the site name and host name must be equal?

Failed to load resource: the server responded with a status of 502 (Bad Gateway)

Cross-Origin request blocked: The same origin policy does not allow remote resources to be read from http://service.einfoszab.budapest.com/api/config/menu. (Cause: The "Access-Control-Allow-Origin" CORS header is missing).

ERROR Object { headers: {…}, status: 0, statusText: "Unknown Error", url: null, ok: false, name: "HttpErrorResponse", message: "Http failure response for (unknown url): 0 Unknown Error", error: error }

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
sada
  • 584
  • 2
  • 8
  • 25
  • 1
    Post the exact error that appears in the browser console – Caius Jard Mar 03 '20 at 22:46
  • You have 502 error problem. You don’t have a CORS problem. The only reason the browser is logging that CORS error is that 502 errors never have the Access-Control-Allow-Origin response header. If you fix the cause of the 502 error, you may likely find that the existing CORS configuration for that endpoint is already working as expected. – sideshowbarker Mar 03 '20 at 23:42
  • Yes, I think you are right. I found that DNS name changing may cause DNS propagation. I restarted IIS, flushed DNS cache but nothing. – sada Mar 03 '20 at 23:57

1 Answers1

-1

Yes you're almost right but it's not Angular blocking those requests, but browser.

To enable CORS you will need to enable cross domain requests on your server side.

I'm not really familiar with ASP.NET, but i think that this link can help you https://jakeydocs.readthedocs.io/en/latest/security/cors.html

  • Thank you for response. The original sites are working and the the test sites are also working without any settings on IIS. The CORS error displayed just when I put the host names of original sites. – sada Mar 03 '20 at 23:06