You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting up roles seems to be a lot harder than I think it should be. Using code first, it appears the tables related to roles were created. But understanding how to enable and populate them is frustrating.
I've found numerous articles explaining how to do it and everyone of them is different. None of the Microsoft articles seems specific to this.
Based on what I've read, I end up with something like this in startup.
publicvoidConfigureServices(IServiceCollectionservices){services.AddDbContext<ApplicationDbContext>(options =>options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));services.AddDefaultIdentity<ApplicationUser>(options =>{options.SignIn.RequireConfirmedAccount=false;}).AddRoles<ApplicationUser>().AddEntityFrameworkStores<ApplicationDbContext>();services.AddRazorPages();// Set the default authentication policy to require users to be authenticatedservices.AddControllers(config =>{varpolicy=newAuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();config.Filters.Add(newAuthorizeFilter(policy));});}
But the call to AddDefaultIdentity raises an exception.
System.InvalidOperationException: 'AddEntityFrameworkStores can only be called with a role that derives from IdentityRole.'
I just want to enable roles and prepopulate the roles with the ones I'm using. Is there no straight forward way documented to do this?
The text was updated successfully, but these errors were encountered:
Setting up roles seems to be a lot harder than I think it should be. Using code first, it appears the tables related to roles were created. But understanding how to enable and populate them is frustrating.
I've found numerous articles explaining how to do it and everyone of them is different. None of the Microsoft articles seems specific to this.
Based on what I've read, I end up with something like this in startup.
But the call to
AddDefaultIdentity
raises an exception.I just want to enable roles and prepopulate the roles with the ones I'm using. Is there no straight forward way documented to do this?
The text was updated successfully, but these errors were encountered: