Closed andy26500 closed 3 years ago
I enable CORS and replace exception handler with my handler for custom error response in WebApiConfig.cs.
It seems like you'll need to also override the ShouldHandle to always return true, per https://stackoverflow.com/a/24634485/113794
Thanks for your help here, @rubens-farias. Closing as the question has been answered.
I enable CORS and replace exception handler with my handler for custom error response in WebApiConfig.cs.
In my html page, I setup "application/json" as contentType of jquery ajax settings. Browser always send preflight request and get success response with CORS header.
The next request for execute code, I except get a custom error message like:
But I get a response without CORS header and I can't access any content in response.
Browser also shows this response has been blocked by CORS policy.
If I comment out code
config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler());
, I will response with CORS header and full stacktrace as content.Please refer Demo code.