TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chriz L
NA
220
50.8k
Web forms - Manage users and roles (Identity 2.2.1 )
Oct 31 2016 5:22 AM
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<IdentityRole>(context);
var roleMgr =
new
RoleManager<IdentityRole>(roleStore);
if
(!roleMgr.RoleExists(role))
{
IdRoleResult = roleMgr.Create(
new
IdentityRole { Name = role });
}
var userMgr =
new
UserManager<ApplicationUser>(
new
UserStore<ApplicationUser>(context));
var appUser =
new
ApplicationUser
{
UserName = user,
Email = email
};
IdUserResult = userMgr.Create(appUser, pass);
if
(!userMgr.IsInRole(user, role))
{
IdUserResult = userMgr.AddToRole(user, role);
}
}
Reply
Answers (
4
)
check if linq conditions has results
AutoComplete textbox(column) in Datagridview from sql Databa