IMemberManager

Using the IMemberManager

IMemberManager has a variety of methods that are useful for managing members in controllers and views. In this article, we'll have a look at how some of these can be used.

For the full list of methods, see the IMemberManager Interface API Documentation.

How to reference IMemberManager

There are different ways to reference IMemberManager:

Dependency Injection

The recommended way is to create a Controller or Service and inject IMemberManager in the constructor:

MemberAuthenticationController.cs
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Security;

namespace UmbracoDocs.Samples;

public class MemberAuthenticationController : Controller
{
    private readonly IMemberManager _memberManager;

    public MemberAuthenticationController(IMemberManager memberManager)
        => _memberManager = memberManager;
}

Views

Alternatively, IMemberManager can be injected directly into a template:

It is advisable to implement Controllers to manage this kind of view logic.

Examples

Finding members

IMemberManager has multiple ways to find members.

FindByIdAsync(string)

Finds a member by their ID

If we want to find a member by Udi or Guid we need to inject IIdKeyMap service:

Find member by Udi

Find member by Guid

FindByEmailAsync(string)

Finds a member by their email.

FindByNameAsync(string)

Finds a member by their login name.

AsPublishedMember(MemberIdentityUser)

The IMemberManager methods returns members as MemberIdentityUser.

Since Members Types are defined like Content Types in Umbraco, members can hold any number of properties. To access these properties, it can be beneficial to convert the member into an IPublishedContent instance.

This is done using AsPublishedMember(MemberIdentityUser)::

GetCurrentMemberAsync()

Returns the currently logged in member if there is one, else returns null value.

GetUserIdAsync()

Returns the ID of a member.

IsLoggedIn()

Checks if the current request contains a logged-in member.

IsMemberAuthorizedAsync(IEnumerable memberTypes, IEnumerable memberGroups, IEnumerable memberIds)

Checks if the current member is authorized as specific member types, member groups or concrete members.

For instance, you can use this method to verify if the current logged in member is part of a specific group:

IsProtectedAsync()

Returns a Task<bool> specifying if the content with a given Umbraco path has public access restrictions set.

MemberHasAccessAsync(string)

Returns a Task<bool> specifying if the currently logged in member has access to the content given its Umbraco path.

ValidateCredentialsAsync(string username, string password)

Validates that specific member credentials are correct (without performing a log-in).

Last updated

Was this helpful?