Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Im building a iHttpHandler based on the tutorial here:
My problem is that Im adding a function which needs info from:
var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
When I add that helper I get an error:
System.ArgumentNullException: 'A value cannot be null.
Does anyone know why theres no value i UmbracoContext? I have put the code in App_Code.
The code is run from the webconfig in the media folder:
<add name="PDFfilter" path="*.pdf" verb="*" type="HttpHandlerSandbox.App_Code.HelloWorldHandler" />
The UmbracoContext is the current umbraco request. Because the request is not entered into umbraco yet, you can not use the UmbracoHelper.
What you could do, but I would not suggest to walk this way.
What do you need this for?
I need it to compare a list of existing media.Urls()'s to the incoming httphandler.
So I take out a complete list of mediaurls from the umbraco context.
When the httphandler is called, it should compare the current request to the list of media, to see if the media it is calling is protected.
Everything else works, but the comparison.
Why should'nt I use the code? Is there a risk?
I actually don't know what to do if context doesnt work, then I might have to make a cronjob and a controller which fires lists into a DB entry every 5 minutes.
Yes, there is a risk.
If you take the complete list of all media urls, your site might because massively slow! You should do as less lookups as possible. Also, most of the media files exists on disk. So you could check if the file exists on disk to continue with your handler.
If you need to protect media, also consider a package like Media Protect.
okay. I have to think about what to do from here.
Thanks for your input, Damiaan, really appreciate it.
Good luck. You aren't tackling the easiest thing.
I ended up stuffing it all into the ApplicationEventHandler with ContentService_Published. Seems to work.
Also installed Entity Framework to put all content into a separate table.
Shouldnt be any problems with Umbraco.Context and ApplicationEventHandler as far as you know..?
Please read https://our.umbraco.org/documentation/Reference/Common-Pitfalls/ there is section on newing up UmbracoContext.
Thanks Ismail. Thats interesting reading. Havent seen that, though I should. A new approach might be needed for this project.
Seems I was lucky this time. My script is accessing via this:
"access each of these services from their own singleton constructs: UmbracoContext.Current and ApplicationContext.Current."
Thanks for input both of you guys.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted