Updating user role using asp.net identity

前端 未结 2 1331
挽巷
挽巷 2021-02-04 18:38

I have the following problem. While using the following code below to change the user\'s current role i am getting an exception with the message like below:

             


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 18:56

    My roles are managed in the seed method of my DbMigrationsConfiguration class and I renamed it like this:

            if (context.Roles.Any(r => r.Name == "User"))
            {
                var store = new RoleStore(context);
                var manager = new RoleManager(store);
                var role = manager.Roles.First(r => r.Name == "User");
    
                role.Name = "NewNameForUser";
                manager.Update(role);
            }
    

提交回复
热议问题