Problem with Roles, please help!
I follow this article to create my own custom user data, then I follow this other to add Admin user and create and asign Admin Role
https://social.technet.microsoft.com/wiki/contents/articles/51333.asp-net-core-2-0-getting-started-with-identity-and-role-management.aspx
but I can not add roles using the UserManager and RoleManager I have this Exception: NotSupportedException: Store does not implement IUserRoleStore<TUser> When try to call "UserManager.AddToRoleAsync"
Thanks
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 431df4fc-4168-cc8f-d053-9b264d2971c1
- Version Independent ID: cd157d04-d596-83fa-6edb-24d52193eb34
- Content: Add, download, and delete custom user data to Identity in an ASP.NET Core project
- Content Source: aspnetcore/security/authentication/add-user-data.md
- Product: aspnet-core
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande
Fixed! Thanks anyway. I must delete the autogenerate IdentityHostingStartup.Configure method
@alcastronava glad you got it fixed.
Just want to thank alcastronava. I didn't see IdentityHostingStartup.Configure was automatically created. Pain in the ass. Thanks for figuring it out!
Welcome!
well, it didnt fix my issue. Everyday I am questioning my decision to choose ms stack!!!!
Everything is so branched out. Either you can not follow their guide since it is fixed to a set of versions that is almost impossible to provide or when you follow it, it does not work. Then you are old oh your bla bla version is bla bla!!!!!
Thanks for the idea you provided, which help me a lot in using Identity in asp.net core 2.2 In asp.net core 2.2, when you need to use the userManager.addToRole(user,role) method to use the role based identity, you can follow the official guidance in here (which is the guidance actually in asp.net core 2.1): https://docs.microsoft.com/zh-cn/aspnet/core/security/authorization/secure-data?view=aspnetcore-2.2
It is actually same and the only different procedure is :
when you meet this chapter :
Add Role services to Identity
Just ignore the official docs and to do the following step :
replace the row
services.AddDefaultIdentity<IdentityUser>().AddEntityFrameworkStores<ApplicationDbContext>();
with
services.AddDefaultIdentity<IdentityUser>().AddRoles<IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>();
in Areas/Identity/Data/IdentityHostingStartup.cs IdentityHostingStartup::Configure method, but not add it in program.cs (the file can't be deleted in asp.net core 2.2)
I have made a duplicate declaration in AddDefaultIdentity at first ( I just follow the guidance and add it in Program.cs, which will remain a same method in IdentityHostingStartup.Configure ). And that brings me a exception : "Store does not implement IUserRoleStore
The project will be updated later in my repos : https://github.com/ZyuHoiMing/UwpHelper , Good Luck :)