For several CORS requests, the browser sends a previous request, named "preflight request", before it sends the actual request for the resource.
It is not enought to use the standard CORS (Cross Origin Resource Sharing) on web.config , in order to solve the problem.
Here you can see the web.config settings, usually arranged to solve the problem :
How to solve the Preflight CORS error "The requested resource does not support http method 'OPTIONS'" using WebApi and Angular7
The issue appears while crossing domains, and relates to POST, PUT, PATCH, and DELETE methods:
here you can see several requests , also from the Angular 7 app, as from POSTMAN :
here you can see several requests , also from the Angular 7 app, as from POSTMAN :
As said, it is not enought to set the web.config to CORS.
Now, usually the browser sends a previous request to the request that you are sending, named "preflight request", before it sends the actual request for the resource. This Preflight request is of OPTIONS type.
If the response headers do not allow the required HTTP METHOD, the browser do not send it.
The problem is, the WebApi app has not an action to process the Preflight OPTIONS request :
Now, usually the browser sends a previous request to the request that you are sending, named "preflight request", before it sends the actual request for the resource. This Preflight request is of OPTIONS type.
If the response headers do not allow the required HTTP METHOD, the browser do not send it.
The problem is, the WebApi app has not an action to process the Preflight OPTIONS request :
That is what the error is trying to say us.
So, just write an action for OPTIONS verb, that only responds an "OK", as this :
So, just write an action for OPTIONS verb, that only responds an "OK", as this :
Now try again. Send a request. The breakpoint will show the OPTIONS request being processed :
Immediately after, the intended request is taken care of:
That solves this issue.
Have a good day :-)
Have a good day :-)
Enjoy Angular.....
by Carmel Schvartzman
כתב: כרמל שוורצמן
by Carmel Schvartzman
כתב: כרמל שוורצמן
Thanks a lot it worked.
ReplyDelete