Suddenly getting CORS errors in a .Net web application
A call from my SPA to the .Net backend, that had been working fine, started going red in my browser DevTools.
POST + Preflight | (failed) net::ERR_CONNECTION_REFUSED
I knew my CORS config hadn’t changed, and in fact the app is built with appBuilder.UseCors(CorsOptions.AllowAll);
While Ducking around for a solution, I caught sight of a little comment on an SO answer, which said “be aware that exceptions will CLEAN off any CORS headers set by the CORS middleware”.
I returned to VS, opened Exception settings, and turned on all CLR exceptions. When I repeated the call into the API, whaddya know, AutoMapper was throwing a silent error.
After I fixed my mapping, the CORS error went away 😊
Happy hacking!