have you tried moving your code to the ApplicationStarted event, the umbraco context might not be ready on ApplicationStarting, hence the naming of the events...
using ContentService is not considered best practice imho
i didn't say it's a problem (1sql call (probably) won't make a difference), but avoid sql round trips whenever you can, which is what content service will do whereas the umbraco helper won't... Consider implementing this code in 1, 2, 50, 1000 event handlers on startup (yes, i'm playing devil's advocate). I just wanted to hightlight the difference
The action I need to take needs to be done during the ApplicationStarting event, so I pretty much assumed that UmbracoContext was off the table at that point - or I should say I did after the usual 'Doh!'
I'll try using ContentService, as I don't think that any performance hit is likely to be an issue for me during the ApplicationStart phase.
var firstRootNode = ApplicationContext.Services.ContentService.GetByLevel(1).FirstOrDefault();
Actually... you can't do that either.
"Resolution is not frozen, it is not yet possible to get values from it."
On checking the documentation (when all else fails, RTFM)
"Never execute any logic or access any Umbraco services in this method"
That's fairly explicit, so it appears that maybe it is actually game-over for accessing that content in the ApplicationStarting event-handler.
However, although I still don't actually understand the relationship of the Umbraco ApplicationStart* events and the global Application_Start event, on doing a bit of testing, it appears that I can actually achieve what I needed (add to the global filters) in the Umbraco ApplicationStarted event-handler, where I can use UmbracoContext and hence UmbracoHelper.
Find RootNode in ApplicationStarting
I need to make a configuration decision in ApplicationStarting() based on a property-value of a node.
To get that node/value I would normally find the rootnode(s) using UmbracoHelper(UmbracoContext.Current) and work from there.
However, I find that UmbracoContext.Current is null at that point, and so that approach won't work.
Is there a way around this, or is it game-over?
Hi MB
Try to use ContentService:
Thanks,
Alex
no game overs with Umbraco !!!
have you tried moving your code to the ApplicationStarted event, the umbraco context might not be ready on ApplicationStarting, hence the naming of the events...
using ContentService is not considered best practice imho
I don't see a big problem to use a content service on application starting event, it's not a page loading event
Dirk, do you think that only IPublishedContent is the best way?
i didn't say it's a problem (1sql call (probably) won't make a difference), but avoid sql round trips whenever you can, which is what content service will do whereas the umbraco helper won't... Consider implementing this code in 1, 2, 50, 1000 event handlers on startup (yes, i'm playing devil's advocate). I just wanted to hightlight the difference
Cheers guys.
The action I need to take needs to be done during the ApplicationStarting event, so I pretty much assumed that UmbracoContext was off the table at that point - or I should say I did after the usual 'Doh!'
I'll try using ContentService, as I don't think that any performance hit is likely to be an issue for me during the ApplicationStart phase.
Actually... you can't do that either.
"Resolution is not frozen, it is not yet possible to get values from it."
On checking the documentation (when all else fails, RTFM)
"Never execute any logic or access any Umbraco services in this method"
That's fairly explicit, so it appears that maybe it is actually game-over for accessing that content in the ApplicationStarting event-handler.
However, although I still don't actually understand the relationship of the Umbraco ApplicationStart* events and the global Application_Start event, on doing a bit of testing, it appears that I can actually achieve what I needed (add to the global filters) in the Umbraco ApplicationStarted event-handler, where I can use UmbracoContext and hence UmbracoHelper.
So... problem side-stepped.
is working on a reply...