Hello,
I want to build an admin panel where the admin can create roles,users, assign users to roles and reset passwords. I'm using Identity 2.2.1 with web forms
I would appreciate any kind of help. Thank you in advance.
I' m having problem with the following two.
Resetting the password
I tried using the default ResetPassword.aspx in Account folder but I get the following error "An error has occurred" .
Create role and assign role at the same time:
I'm using the following code:
- protected void btnAssignRole_Click1(object sender, EventArgs e)
- {
- RoleActions role = new RoleActions();
- role.AddUserAndRole(roleTxt.Text, userTxt.Text, emailTxt.Text, passTxt.Text);
- }
but I get the following error "An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code. Additional information: UserId not found." in RoleActions.cs
- internal void AddUserAndRole(String role, String user, String email, String pass)
- {
- Models.ApplicationDbContext context = new ApplicationDbContext();
- IdentityResult IdRoleResult;
- IdentityResult IdUserResult;
- var roleStore = new RoleStore
(context); - var roleMgr = new RoleManager
(roleStore); - if (!roleMgr.RoleExists(role))
- {
- IdRoleResult = roleMgr.Create(new IdentityRole { Name = role });
- }
- var userMgr = new UserManager
( new UserStore(context)); - var appUser = new ApplicationUser
- {
- UserName = user,
- Email = email
- };
- IdUserResult = userMgr.Create(appUser, pass);
- if (!userMgr.IsInRole(user, role))
- {
- IdUserResult = userMgr.AddToRole(user, role);
- }
- }
Chriz LPosted Nov 1, 2016, 8:30 AM
Bikesh SrivastavaPosted Nov 1, 2016, 8:05 AM
Chriz LPosted Nov 1, 2016, 2:53 AM
Nitin SontakkePosted Oct 31, 2016, 6:09 AM