Parameter name: umbracoContext at
Umbraco.Web.UmbracoHelper..ctor(UmbracoContext umbracoContext) at
umbraco.library.IsProtected(Int32 DocumentId, String Path) at
WebSite.Extensions.ExamineEvents.InjectGroups(IndexingNodeDataEventArgs
e) in D:\projects\WebSite\Extensions\ExamineEvents.cs:line
34 2016-10-06 17:18:56,938 [P10464/D2/T8] ERROR
WebSite.Extensions.ExamineEvents - Value cannot be null.
There is my full code:
public class ExamineEvents : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ExamineManager.Instance.IndexProviderCollection["globalIndexer"].GatheringNodeData += ExamineEvents_GatheringNodeData;
}
private void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
InjectGroups(e);
}
private void InjectGroups(IndexingNodeDataEventArgs e)
{
try
{
var node = new Node(e.NodeId);
if (umbraco.library.IsProtected(node.Id, node.Path))
{
var groups = Access.GetAccessingMembershipRoles(node.Id, node.Path);
var groupsAccess = new StringBuilder();
foreach (var group in groups)
{
groupsAccess.Append(group);
groupsAccess.Append(" ");
}
e.Fields.Add("GroupAccess", groupsAccess.ToString().Trim());
e.Fields.Add("IsPublic", "false");
}
else
{
e.Fields.Add("GroupAccess", "0");
e.Fields.Add("IsPublic", "true");
}
}
catch (Exception ex)
{
LogHelper.Error(GetType(), ex.Message, ex);
}
}
}
Any ideas how to resolve it? (Umbraco version 7.4.3)
I did not know about this service.
Now I replaced umbraco.library.IsProtected(node.Id, node.Path) method on ApplicationContext.Current.Services.PublicAccessService.IsProtected(node.Path)
I suspect the new Node is giving you null. The parameters that you need are in the e.Fields collection so you could them from there and therefore no need to new up new node? So
e.Fields["path"] you already have node id e.NodeId
Also as pointed out by Alex umbraco.library is old and deprecated.
Filed "path" does not exist in Fields property, I was checked it.
I think, on event ApplicationStarted - umbraco cant create instance of UmbracoHelper because Umbraco.Core.ApplicationContext.Current is null at this moment.
Secure searching - role based protection
Hi community,
I need implement role based protection for search results. I do it as in this blog-post http://thecogworks.co.uk/blog/2013/03/15/examiness-hints-and-tips-from-the-trenches-part-9-secure-searching but in my case I catch exception when call method umbraco.library.IsProtected(int DocumentId, string Path) where says:
There is my full code:
Any ideas how to resolve it? (Umbraco version 7.4.3)
Regards, Ivan.
Hi Ivan,
Interesting issue, did you try to use services?
I think you have to use PublicAccessService, read more here -
https://our.umbraco.org/apidocs/csharp/api/Umbraco.Core.Services.PublicAccessService.html
Thanks,
Alex
Hi Alex,
Thanks for the reply.
I did not know about this service. Now I replaced umbraco.library.IsProtected(node.Id, node.Path) method on ApplicationContext.Current.Services.PublicAccessService.IsProtected(node.Path)
And it works, many thanks :)
Regards, Ivan.
Ivan,
No need to new up new node you can get what you need from e.Fields will be quicker.
Yeah, now I do not create instance of Node, thanks.
Ivan,
I suspect the new Node is giving you null. The parameters that you need are in the e.Fields collection so you could them from there and therefore no need to new up new node? So
e.Fields["path"] you already have node id e.NodeId
Also as pointed out by Alex umbraco.library is old and deprecated.
Regards
Ismail
Hi Ismail,
Filed "path" does not exist in Fields property, I was checked it.
I think, on event ApplicationStarted - umbraco cant create instance of UmbracoHelper because Umbraco.Core.ApplicationContext.Current is null at this moment.
Regards, Ivan.
Ivan,
I have done
On all my search projects, works fine.
Regards
Ismail
Ismail, it is very strange, I do not have "path" in e.Fields. See attached screenshot above.
Regards, Ivan.
is working on a reply...