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
Steve Moro
NA
16
586
ASP.NET CORE 2.0 AppRole Management
Apr 22 2018 7:35 PM
Is there any View Model and CSHTML example of how to manage Add/Edit/Delete Roles from a User.
I have read that you can programatically register user and add Roles using
public
static
async Task CreateUserRoles(IServiceProvider serviceProvider)
{
var RoleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
var UserManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
IdentityResult roleResult;
//Adding Addmin Role
var roleCheck = await RoleManager.RoleExistsAsync(
"Admin"
);
if
(!roleCheck)
{
//create the roles and seed them to the database
roleResult = await RoleManager.CreateAsync(
new
IdentityRole(
"Admin"
));
}
roleCheck = await RoleManager.RoleExistsAsync(
"Sales"
);
if
(!roleCheck)
{
//create the roles and seed them to the database
roleResult = await RoleManager.CreateAsync(
new
IdentityRole(
"Sales"
));
}
roleCheck = await RoleManager.RoleExistsAsync(
"Customer"
);
if
(!roleCheck)
{
//create the roles and seed them to the database
roleResult = await RoleManager.CreateAsync(
new
IdentityRole(
"Customer"
));
}
//Assign Admin role to the main User here we have given our newly loregistered login id for Admin management
ApplicationUser user = await UserManager.FindByEmailAsync(
"
[email protected]
"
);
var User =
new
ApplicationUser();
await UserManager.AddToRoleAsync(user,
"Admin"
);
}
However when the application is running I need an application admin to administer Application Roles with users.
Reply
Answers (
0
)
paytm integration with demo account (asp.net C#)
How to translate english to kannada using MVC dot net