Can anyone explain how to access or instantiate the Umbraco core services inside an http module. I can't seem to get it working.
public void OnBeginRequest(Object sender, EventArgs e)
{
var httpApp = (Umbraco.Web.UmbracoApplication)sender;
// how the heck do i get to the services?
var myMedia = Umbraco.Core.ApplicationContext.Current.Services.MediaService.GetById(1000);
// myMedia is always null
}
I'm trying to intercept the requests before some other modules (ie the imageprocessor).
That was actually a placeholder for this post, but shoot you might be right. I was thinking that the URL /media/1001/file.png had the id in it but it looks like that is a wrong assumption..... So now I need to see how I can map the file name to a media item....
Use ContentService/MediaService inside HttpModule
Umbraco v7.x
Can anyone explain how to access or instantiate the Umbraco core services inside an http module. I can't seem to get it working.
I'm trying to intercept the requests before some other modules (ie the imageprocessor).
Thanks.
HI,
You could always do the following, although it doesn't use any of the services.
Thanks, Dan.
UmbracoContext.Current is null so it won't work.
Are you sure you have a media item with an ID of 1000?
Because the fact that you can make the call without any NullReferenceExceptions kind of proves that the service has been instantiated alright.
That was actually a placeholder for this post, but shoot you might be right. I was thinking that the URL /media/1001/file.png had the id in it but it looks like that is a wrong assumption..... So now I need to see how I can map the file name to a media item....
is working on a reply...