Umbraco 6.1.5, Media Protect 1.1.12. Unlicensed version, running on localhost.
In the media section I have set up role based protection on a folder. Within that folder I have a number of files. The folder and files have the icon that imply they are protected.
I'm indexing a lucene index and have cause to add a field using GatheringNodeData. See code below (not streamlined yet as I'm testing it):
public class ExamineEvents : IApplicationEventHandler { public ExamineEvents() { ExamineManager.Instance.IndexProviderCollection["SiteSearchIndexer"].GatheringNodeData += new EventHandler<IndexingNodeDataEventArgs>(ExamineEvents_GatheringNodeData); }
Any protected content types are correctly assigned IsProtected=true, but all media types (protected or unprotected) are assigned IsProtected=false.
I did try using:
if (MediaProtect.Library.Library.IsProtected(int.Parse(e.Node.Attribute("id").Value), e.Node.Attribute("path").Value))
for the media types, but get a null reference exception. I think because IsProtected calls umbraco.library.IsProtected method, which requires HttpContext. But I'm not sure of this.
MediaProtect.Access.MediaAccess.IsProtected()
The above method also fails with null reference exception.
Is there some other way to check if a node is protected whilst running an Examine / Lucene indexing operation?
This is weird. There will be a call to umbraco.library.IsProtected indeed but only when item is of type content. But Media protect uses HTTPContext internally also so that might be the issue. So you are saying that you can't use HTTPContext when indexing using Examine?
Making any call to the MediaProtect API is causing a null reference exception when calling IsProtected against a media item within the Examine GatheringNodeData event. We need to add an indexing property to show if a media item is protected or not. Perhaps there is another way to do this?
Will add this to my list to implement also(will not be in the next few days/weeks sorry). I like the way you want to solve this. Most customers I have use the IsProtected method when rendering the overview. This is because you can change the protection without saving the node. Also possible for you to use maybe?
But protected data is stored in app_data/mediaaccess.config file. Also possible to use that, but not ideal I think.
That's a shame. I was following this post which said it was possible to do what I wanted to do with MediaProtect. I'll have to come up with a work around as I can't wait, unfortunately. Anyway, thanks for coming back to me.
The method MediaProtect.Library.AllowedGroups() isn't there. But there is a static MediaProtect.Library.Library.AllowedGroups() method, which is the one I'm trying to use. The method gives the same error as MediaProtect.Library.Library.IsProtected():
System.NullReferenceException was unhandled HResult=-2147467261 Message=Object reference not set to an instance of an object. Source=MediaProtect StackTrace: at MediaProtect.Configuration.Config.get_MediaAccessFile() at .() at .(Int32 ) at MediaProtect.Access.MediaAccess.AllowedGroups(Int32 mediaId, String path) InnerException:
I assume this is the same problem. Is there another way to call those methods? Maybe an instance method rather than static?
Strangely, it looks like umbraco.cms.businesslogic.web.Access.IsProtected() method does access httpcontext, so maybe there is something else going on. Although maybe the umbraco method isn't hitting httpcontext because it's accessing a cache...
That's the method to use Mediaprotect.Libary is used in XSLT which came before razor. But the HTTPContext is in another method that is used by the library. I think I can rid of the HTTPContext in my own library but it makes calls to Umbraco also.
But still weird that HTTPContext is throwing exceptions in this index methods.
Added this class (uncomment the commented line, also add reference to MediaProtect.dll):
using System; using System.Collections.Generic; using System.Linq; using System.Web; using Umbraco.Core; using Examine; using umbraco.cms.businesslogic.web;
namespace MyNameSpace { public class ExamineEvents : IApplicationEventHandler { public ExamineEvents() { ExamineManager.Instance.IndexProviderCollection["SiteSearchIndexer"].GatheringNodeData += new EventHandler(ExamineEvents_GatheringNodeData); }
Hi Mark when trying to compile I get the following error
Error 1 No overload for 'ExamineEvents_GatheringNodeData' matches delegate 'System.EventHandler' f:\temp\examinetest\MediaProtectExamine\MediaProtectExamine\ExamineEvents.cs 15 103 MediaProtectExamine
This error is in the constructor
public ExamineEvents()
{
ExamineManager.Instance.IndexProviderCollection["SiteSearchIndexer"].GatheringNodeData += new EventHandler(ExamineEvents_GatheringNodeData);
}
I thought it was released already but it isn't sorry. I will release it next week. If you need the package before send me an email please [email protected] and I'll send it.
Did you upgrade from a previous version? Mediaprotect V2 just instatiates the concrete object without loading dll's so I am curious what is causing this?
I'm having this same issue on Umbraco 7.65 and MediaProtect 2.0.0.
I'm calling AllowedGroups to add properties to my Examine document index.
I noticed that after I lauch the site, I can save a file as many times as I want and it's ok. When I try to save another file, I get the error. It's not file related, tested with different files.
The error occurs always when I rebuild the index, even on the first file (iteration).
System.ArgumentNullException occurred
HResult=0x80004003
Message=Value cannot be null.
Parameter name: httpContext
Source=MediaProtect.Core
StackTrace:
at MediaProtect.Core.Helpers.ContextHelper.EnsuredContext()
at MediaProtect.Access.MediaAccess.AllowedGroups(String fileName)
at MediaProtect.Library.Library.AllowedGroups(String fileName)
at CRT.SocialIntranet.Web.Utils.AppEvents.GatheringContentDocumentsData(Object sender, IndexingNodeDataEventArgs e, UmbracoHelper helper) in path 253
at path.<>c__DisplayClass2_0.<OnApplicationStarted>b__5(Object sender, IndexingNodeDataEventArgs e) in path:line 71
at Examine.Providers.BaseIndexProvider.OnGatheringNodeData(IndexingNodeDataEventArgs e)
at UmbracoExamine.UmbracoContentIndexer.OnGatheringNodeData(IndexingNodeDataEventArgs e)
at Examine.LuceneEngine.Providers.LuceneIndexer.GetDataToIndex(XElement node, String type)
at Examine.LuceneEngine.Providers.LuceneIndexer.ProcessIndexQueueItem(IndexOperation op, IndexWriter writer)
at Examine.LuceneEngine.Providers.LuceneIndexer.ProcessQueueItem(IndexOperation item, ICollection`1 indexedNodes, IndexWriter writer)
at Examine.LuceneEngine.Providers.LuceneIndexer.ForceProcessQueueItems(Boolean block)
I was able to instantiate the HttpContext with a call to UmbracoContext.EnsureContext(helper.UmbracoContext.HttpContext, ... )
Although, it would be much cleaner if I could pass helper.UmbracoContext.HttpContext as a parameter to an overload of your functions. Would that be possible?
IsProtected bug?
Umbraco 6.1.5, Media Protect 1.1.12. Unlicensed version, running on localhost.
In the media section I have set up role based protection on a folder. Within that folder I have a number of files. The folder and files have the icon that imply they are protected.
I'm indexing a lucene index and have cause to add a field using GatheringNodeData. See code below (not streamlined yet as I'm testing it):
Any protected content types are correctly assigned IsProtected=true, but all media types (protected or unprotected) are assigned IsProtected=false.
I did try using:
for the media types, but get a null reference exception. I think because IsProtected calls umbraco.library.IsProtected method, which requires HttpContext. But I'm not sure of this.
The above method also fails with null reference exception.
Is there some other way to check if a node is protected whilst running an Examine / Lucene indexing operation?
Hi,
This is weird. There will be a call to umbraco.library.IsProtected indeed but only when item is of type content. But Media protect uses HTTPContext internally also so that might be the issue. So you are saying that you can't use HTTPContext when indexing using Examine?
Thanks,
Richard
Making any call to the MediaProtect API is causing a null reference exception when calling IsProtected against a media item within the Examine GatheringNodeData event. We need to add an indexing property to show if a media item is protected or not. Perhaps there is another way to do this?
@Richard could we make a database call directly?
Hi Mark,
Will add this to my list to implement also(will not be in the next few days/weeks sorry). I like the way you want to solve this. Most customers I have use the IsProtected method when rendering the overview. This is because you can change the protection without saving the node. Also possible for you to use maybe?
But protected data is stored in app_data/mediaaccess.config file. Also possible to use that, but not ideal I think.
Best,
Richard
Hi Richard,
That's a shame. I was following this post which said it was possible to do what I wanted to do with MediaProtect. I'll have to come up with a work around as I can't wait, unfortunately. Anyway, thanks for coming back to me.
Mark
Hi Mark,
Did you try that exact method also in that blogpost?
Thanks,
Richard
Hi Richard,
The method MediaProtect.Library.AllowedGroups() isn't there. But there is a static MediaProtect.Library.Library.AllowedGroups() method, which is the one I'm trying to use. The method gives the same error as MediaProtect.Library.Library.IsProtected():
I assume this is the same problem. Is there another way to call those methods? Maybe an instance method rather than static?
Thanks,
Mark
Strangely, it looks like umbraco.cms.businesslogic.web.Access.IsProtected() method does access httpcontext, so maybe there is something else going on. Although maybe the umbraco method isn't hitting httpcontext because it's accessing a cache...
Hi Mark,
That's the method to use Mediaprotect.Libary is used in XSLT which came before razor. But the HTTPContext is in another method that is used by the library. I think I can rid of the HTTPContext in my own library but it makes calls to Umbraco also.
But still weird that HTTPContext is throwing exceptions in this index methods.
Maybe it isn't httpcontext. Are you able to reproduce the issue?
Added toExamineIndex.config:
Added to ExamineSettings.config:
Added this class (uncomment the commented line, also add reference to MediaProtect.dll):
I'd like to make sure I'm not doing something wrong...
Hi Mark,
I'll setup a dev environment to reproduce thanks for the detailed instructions.
Thanks,
Richard
Hi Mark when trying to compile I get the following error
Error 1 No overload for 'ExamineEvents_GatheringNodeData' matches delegate 'System.EventHandler' f:\temp\examinetest\MediaProtectExamine\MediaProtectExamine\ExamineEvents.cs 15 103 MediaProtectExamine
This error is in the constructor
Any ideas? Also possible to mail me [email protected]
Thanks,
Richard
Going back and forth with Mark. The issue was related to the use of HTTPContext in Media protect library indeed. V1.5.1 will solve this.
@Richard - thanks for all your help. Problem solved. I'll mark your answer. I'll also order a Media Protect license for this project shortly.
Mark
Hi Mark,
Thanks for both!
Best,
Richard
Hi Richard,
Is v1.5.1 available yet? We are seeing the same issue in our GatheringNodeData event, in a call to MediaProtect.Library.Library.IsProtected.
Thanks,
Mike
Hi Michael,
I thought it was released already but it isn't sorry. I will release it next week. If you need the package before send me an email please [email protected] and I'll send it.
Best,
Richard
Hi
Im having the same problem, but im running MediaProtect on version 2.0
I get: The value should not be null. Parametername: httpContext
On this piece of code inside the GatheringNodeData event:
Is there anything im missing? Or is this broken again?
Best regards
Nils
Hi,
Did you upgrade from a previous version? Mediaprotect V2 just instatiates the concrete object without loading dll's so I am curious what is causing this?
Best,
Richard
Hi Richard,
we only installed it from the NuGet Store, so no upgrades.
Best regards Nils
Hello,
I'm having this same issue on Umbraco 7.65 and MediaProtect 2.0.0.
I'm calling AllowedGroups to add properties to my Examine document index.
I noticed that after I lauch the site, I can save a file as many times as I want and it's ok. When I try to save another file, I get the error. It's not file related, tested with different files. The error occurs always when I rebuild the index, even on the first file (iteration).
Thanks,
Mário
Mediaprotect needs HTTPContext which is not available in Examine. You can request acces rights at runtime.
Hope this helps,
Richard
Hi,
That helped!
I was able to instantiate the HttpContext with a call to UmbracoContext.EnsureContext(helper.UmbracoContext.HttpContext, ... )
Although, it would be much cleaner if I could pass helper.UmbracoContext.HttpContext as a parameter to an overload of your functions. Would that be possible?
Thanks,
Mário
is working on a reply...