Custom route on UmbracoApiController disables gett...
# help-with-umbraco
k
IUmbracoHelperAccessor.TryGetUmbracoHelper()
stops working "could not get context" if I slap e.g.,
[Route("MyRoute")]
on an action method in an
UmbracoApiController
. Is it because the route is no longer
/umbraco/api/something
and the context cannot be determined? Is there a workaround?
s
Probably because the route is no longer that yeah, can't remember exactly. You should be able to make a service that constructs an umbraco context so you can call it from your api controller. The second code block here gets an
IPublishedContentQuery
assuming you are trying to get published content from the cache - https://cultiv.nl/blog/using-hangfire-to-update-umbraco-content/
j
Have you tried looking at the Swagger page to see what routes are enabled?
k
There's only the Delivery API there. The "Default API" has no operations. Not sure what you mean by "routes are enabled"? This is a custom API controller (
UmbracoApiController
) that can use the Umbraco helper accessor fine when running on the default route but not on the custom route. I haven't decorated the controller in a way that the built-in Swagger would pick up. (But maybe I should.)
2 Views