0
votes

I am implementing ASP.NET Identity via RavenDB and try to add roles to my user. https://github.com/ILMServices/RavenDB.AspNet.Identity/blob/master/RavenDB.AspNet.Identity/UserStore.cs

This implementation has the following overload available public Task AddToRoleAsync(TUser user, string role)

The ApplicationUserManager is derived from UserManager but I am unable to reach the overload. The only method available is the base method AddToRoleAsync(string UserId, string role).

The Store property is a public property in the UserManager base class, so it doesn't look anything special is going on there.

I also tried doing a direct call to manager.Store.AddToRoleAsync but again I am not getting the overloaded method back with intellisense.

I hope someone can guide me in the right direction, really stuck here.

When I create the UserStore the member is accessible: After I created the ApplicationUserManager with the UserStore the member is hidden And then ofcourse my controller inherits this issue, and this started my search to why this is happening.

Controller Action

In Reponse to CodeNotFound, here is the ApplicationUser. It is quite simple.

   public class ApplicationUser : IdentityUser, IEntity
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime Created { get; set; }
        public DateTime Modified { get; set; }


        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            // Add custom user claims here
            return userIdentity;
        }
    }
1
can show us the code of your ApplicationUser ?CodeNotFound
I added the class to my initial postMicha Schopman

1 Answers

0
votes

It is because you need to write in your custom ApplicationUserManager like this

    /// <summary>
    /// Method to add user to multiple roles
    /// </summary>
    /// <param name="userId">user id</param>
    /// <param name="roles">list of role names</param>
    /// <returns/>
    public Task<IdentityResult> AddToRolesAsync(string userId, string[] roles)
    {
        return yourrolestore.AddToRolesAsync(userId, roles.GetStringArray());
    }

Because like you wrote, UserManager didn't know your defined UserStore. You must do the link manually

EDIT

When you extend UserManager you MUST specify the type of Key. So in your case type this :

UserManager<ApplicationUser, int>

And normally you will found your overload method with int key in parameter.