Umbraco Rest API and UmbracoApiController CORS conflicting
Hi everyone,
I managed to install the new Umbraco Rest API and I was starting creating an Angularjs App with Restangular.
I wanted create a method to export the website menu and use it in the Angular JS app. In the new Umbraco Rest Api there is no method to return the children of the root node without also returning all the properties. This has a big drawback for websites with lot of contents. In order to populate dynamically the menu you have also to load all the contents.
Therefore, I thought to create a API which inherits from the UmbracoApiController and exports the menu.
The problem is with the CORS policy. The Umbraco Rest Api CORS policy conflicts with the usual CORS policy I have always used to make Umbraco API controllers accessible from a different domain.
You can find the post at
https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/63841-Web-API-2-and-cross-origin-resource-sharing-CORS
Umbraco Rest API and UmbracoApiController CORS conflicting
Hi everyone,
I managed to install the new Umbraco Rest API and I was starting creating an Angularjs App with Restangular. I wanted create a method to export the website menu and use it in the Angular JS app. In the new Umbraco Rest Api there is no method to return the children of the root node without also returning all the properties. This has a big drawback for websites with lot of contents. In order to populate dynamically the menu you have also to load all the contents. Therefore, I thought to create a API which inherits from the UmbracoApiController and exports the menu. The problem is with the CORS policy. The Umbraco Rest Api CORS policy conflicts with the usual CORS policy I have always used to make Umbraco API controllers accessible from a different domain. You can find the post at https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/63841-Web-API-2-and-cross-origin-resource-sharing-CORS
I started digging in the source code of the Umbraco Rest API, https://github.com/umbraco/UmbracoRestApi, and I found this attribute [DynamicCors] on https://github.com/umbraco/UmbracoRestApi/blob/master/src/Umbraco.RestApi/Controllers/UmbracoHalControllerBase.cs.
I thought that adding the attribute on my API controller inheriting from UmbracoApiController could have solved the issue, but it didn't.
Is there anything that I can do to solve my issue?
Thanks in advance
Enrico
I found the solution! The solution was setting the header from the controller method.
I will share it for anyone who may need it.
is working on a reply...