CORS problem with API. HTTP OPTIONS call returns 405
Hi,
I have added a WebAPI to my Umbraco 8 site, by subclassing UmbracoApiController. Calling the WebAPI using Postman works fine, but when calling it from an external web app it fails. I am getting problems with CORS in the browser. It says OPTIONS {myendpoint} 405 (Method Not Allowed) and Access to {myendpoint} has been blocked by CORS policy: Response to preflight request doesn't pass access control check
I have modified the web.config file to add the headers required by CORS ('Access-Control-Allow-Origin' and 'Access-Control-Request-Headers') and verified with Postman they are correct. In short:
HTTP POST {mysite}/umbraco/api/{mystuff} works fine and has correct CORS headers.
HTTP OPTIONS {mysite}/umbraco/api/{mystuff} fails with 405.
Found this code snippet on how to add CORS, but that code is for Umbraco 7 and doesn't even compile for Umbraco 8.
CORS problem with API. HTTP OPTIONS call returns 405
Hi,
I have added a WebAPI to my Umbraco 8 site, by subclassing
UmbracoApiController
. Calling the WebAPI using Postman works fine, but when calling it from an external web app it fails. I am getting problems with CORS in the browser. It saysOPTIONS {myendpoint} 405 (Method Not Allowed)
andAccess to {myendpoint} has been blocked by CORS policy: Response to preflight request doesn't pass access control check
I have modified the web.config file to add the headers required by CORS ('Access-Control-Allow-Origin' and 'Access-Control-Request-Headers') and verified with Postman they are correct. In short:
HTTP POST {mysite}/umbraco/api/{mystuff}
works fine and has correct CORS headers.HTTP OPTIONS {mysite}/umbraco/api/{mystuff}
fails with 405.Found this code snippet on how to add CORS, but that code is for Umbraco 7 and doesn't even compile for Umbraco 8.
Any ideas?
Solved the problem!
Had to do two things.
[HttpOptions]
header to my controller action.web.config
MyController.cs
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.