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
Marius Vasile
590
1.9k
149k
.NET Core Razor- New Roles assigned after registration
Jun 7 2020 2:18 AM
I can assign a role at Registration level e.g Visitor, but how do I manage to change that role from User/Edit page? Also, how to add all the roles required to aspnetrole and then assign to users as needed?
Model
public
class
UserDataClass : IdentityUser
{
public
string
UserOrganization {
get
;
set
; }
public
string
UserStatus {
get
;
set
; }
public
UserRoleList URole {
get
;
set
; }
public
ICollection<AppUserRole> UserRoles {
get
;
set
; }
}
public
class
UserRoleClass : IdentityRole
{
public
string
UsRole {
get
;
set
; }
}
public
class
AppUserRole : IdentityUserRole<
string
>
{
public
virtual
UserDataClass UsName {
get
;
set
; }
public
virtual
UserRoleClass UsRole {
get
;
set
; }
}
public
enum
UserRoleList
{
Admin = 0,
UserAdmin = 1,
Management = 2,
Visitor = 3
}
Registration - assign Visitor (working)
if
(!await _roleManager.RoleExistsAsync(
"Visitor"
))
{
var role =
new
IdentityRole(
"Visitor"
);
var res = await _roleManager.CreateAsync(role);
if
(res.Succeeded)
{
await _userManager.AddToRoleAsync(user,
"Visitor"
);
await _signInManager.SignInAsync(user, isPersistent:
false
);
_logger.LogInformation(
"A new account was created"
);
}
}
startup
services.AddIdentity<UserDataClass, UserRoleClass>(options => options.SignIn.RequireConfirmedAccount =
true
)
.AddDefaultUI()
.AddRoles<UserRoleClass>()
Reply
Answers (
6
)
how to dynamic chain system find parent in c#
Payment gateway callback action method executing multiple