How to access member data in the form of IPublishedContent in Umbraco 9?
Hello.
Basically I'm looking for MembershipHelper in Umbraco 9. Seems like it's no longer available. The purpose is accessing properties of custom member which i have created.
and resolving the id from Udi or Guid by injecting IIdKeyMap service.
Find member by id
var memberById = await _memberManager.FindByIdAsync("1234");
IPublishedContent member = _memberManager.AsPublishedMember(memberById);
Find member by udi
var memberUdiAttempt = _idKeyMap.GetIdForUdi(nodeUdi);
if (memberUdiAttempt.Success)
{
var memberId = memberUdiAttempt.Result;
var member = await _memberManager.FindByIdAsync(memberId.ToString());
}
Find member by key
var memberKeyAttempt = _idKeyMap.GetIdForKey(nodeKey);
if (memberKeyAttempt.Success)
{
var memberId = memberKeyAttempt.Result;
var member = await _memberManager.FindByIdAsync(memberId.ToString());
}
How to access member data in the form of IPublishedContent in Umbraco 9?
Hello.
Basically I'm looking for MembershipHelper in Umbraco 9. Seems like it's no longer available. The purpose is accessing properties of custom member which i have created.
Hi
I noticed a similar question the other day: https://our.umbraco.com/forum/using-umbraco-and-getting-started/107936-how-to-get-member-by-udi-in-umbraco-9
In Umbraco 9 there is no longer a
MemberShipHelper
, but now aIMemberManager
which one can inject in controllers or views: https://our.umbraco.com/documentation/reference/querying/IMemberManager/and resolving the id from
Udi
orGuid
by injectingIIdKeyMap
service.Find member by id
Find member by udi
Find member by key
I have submitted a PR here to update the documentation: https://github.com/umbraco/UmbracoDocs/pull/3752
If using a member picker this should already be handled in the PVC: https://github.com/umbraco/Umbraco-CMS/blob/v9/contrib/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs
And the same goes for MNTP: https://github.com/umbraco/Umbraco-CMS/blob/v9/contrib/src/Umbraco.Core/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs
This solves my problem, im very grateful :)
You're welcome :)
Ensure to mark the solution to solved as it may help others..
is working on a reply...