Manage user roles in asp net core identity

preview_player
Показать описание

Text version of the video

Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.

Slides

ASP.NET Core Text Articles & Slides

ASP.NET Core Tutorial

Angular, JavaScript, jQuery, Dot Net & SQL Playlists
Рекомендации по теме
Комментарии
Автор

Hello Mr Venkat,
I think the most important thing in this video is the checkbox binding technique. Very useful.
I am stil looking forward to your Blazor tutorial and also end-to-end real life enterprise solution tutorials with faster videos without too much explanations.
Your tutorials are excellent as always. Thanks.

kourosh
Автор

Hi @kudvenkat, thank you very much for putting so much effort and time for tutorial.. for me your tutorial is like Bhagvat Geeta, As many times as i watch i learn something new all the time. Thank a lot man!!

kaushikbhadani
Автор

I followed along until this far, and am happy with your work sir. Thanks you for your effort.

mystique
Автор

Special thanks for giving much time on mvc core SECURITY videos. It REALLY deserves that much attention. Kindly start a tutorial series in Azure. Most awaited.

studentfeedback
Автор

Hi Venkat Sir,
You are simply great...
Please do tutorials on ms Azure, cosmos db, azure functions, service bus thanks

prakashbuchade
Автор

Thank You, Very Mush For Your Work and Your Effort

majdafannan
Автор

How did you send userId to public async Task<ActionResult> model, string userId)
?!

amirkian
Автор

Please, What is the point of using <input> instead of <button> to submit the form?

hossammetwally
Автор

Kudvenkat Sir, the statement "await userManager.IsInRoleAsync(user, role.Name)" doesn't work in asp.net core 3.1 so that can you please give me an updated statement to handle the exception : {"There is already an open DataReader associated with this Command which must be closed first."}?

rizwanaslam
Автор

Dear Venkat, please explain me how the post method can receive the userId ? If i comment the ViewBag in the ManageUserRoles the userId however arrive to the post method.
Why ?
Thanks a lot.

marcol
Автор

Is there any scaffolding of that Manage/Roles page or did you HTML that yourself?

prototype
Автор

Hi and thank you for really great job. I get following error when checking if user is in role (on "await _userManager.IsInRoleAsync(user, role.Name)"): "InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first."

imarijanovic
Автор

i have problem, if i update roles then the existing roles which i do not check are removed

ypwygk
Автор

How is userId being passed to the post action method? I don't see it being included as a hidden input field anywhere.

JayJay-nbsv
Автор

I was getting error,


"InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first. asp.net core".


My .Net Core version was 3.1.


My Solution:
Added in connection string.


Reason (Not Sure):
May be my DbContext is already in use and parallel task also needs that same instance Context. So it was throwing error.


I was getting this error on below Code to check user in role.

if (await userManager.IsInRoleAsync(user, role.Name))

{
userRolesViewModel.IsSelected = true;
}
else
{
userRolesViewModel.IsSelected = false;
}



Hope this help someone.
Thanks.

jainamshah
Автор

Dear Venkat,

Could you kindly explain why do we need to remove all the existing user roles using the RemoveFromRolesAsync() method of the userManager service, before adding all the roles that the user has selected on the UI using the AddToRolesAsync() method of the userManager service ???

var roles = await
var result = await userManager.RemoveFromRolesAsync(user, roles);

result = await userManager.AddToRolesAsync(user,
model.Where(x => x.IsSelected).Select(y => y.RoleName));

ymtan
Автор

I'm getting error here.
result= await User manager.AddToRoleAsync(user,


Error is this

Argument 2: cannot convert from to string

Please reply me. I am working on my college project by following your tutorials.

EnGamology
Автор

Could you explain me, please.
Why do you have:

but I have:

lordjim
Автор

I have using razor pages and get following error please help if anyone known about multiple constructor

An unhandled exception occurred while processing the request.
InvalidOperationException: Multiple constructors accepting all given argument types have been found in type There should only be one applicable constructor.

my code is below

public class EditRolesInUserModel : PageModel
{
private readonly RoleManager<IdentityRole> roleManager;
private readonly UserManager<IdentityUser> userManager;

public EditRolesInUserModel
(RoleManager<IdentityRole> roleManager, UserManager<IdentityUser> userManager)
{
this.roleManager = roleManager;
this.userManager = userManager;

}
public InputModel Input { get; set; }

public class InputModel
{
public string RoleId { get; set; }
public string RoleName { get; set; }
public bool IsSelected { get; set; }
};
public async Task<IActionResult> OnGetAsync(string Id)
{
var user = await

if (user == null)
{
return Page();
}

var model = new List<InputModel>();
foreach(var role in roleManager.Roles)
{
var inputmodel = new InputModel
{
RoleId = role.Id,
RoleName = role.Name
};
if(await userManager.IsInRoleAsync(user, role.Name))
{
inputmodel.IsSelected = true;
}else
{
inputmodel.IsSelected = false;
}
model.Add(inputmodel);
}
return RedirectToPage("EditRolesInUser", model);
}
}

arvindborayan
Автор

Dear Venkat, could you kindly explain the following code that is present in HttpPost ManageUserRoles Action because I don't really understand the code ???


result = await userManager.AddToRolesAsync(user,
model.Where(x => x.IsSelected).Select(y => y.RoleName));

ymtan