简体   繁体   中英

ASP.NET CORE Roles - Add IdentityRole

Im trying to add roles functionality to my app but I'm getting an error message that I don't really understand or know how to fix it.

Im trying to add The IdentityRole to services.AddIdentityCore but getting an error message:

"'IServiceCollection' does not contain a definition for 'AddIdentityCore' and no accessible extension method 'AddIdentityCore' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?) [API]csharp(CS1061)

在此处输入图片说明

Does anyone know how to implement it right? What causes this issue ? Thanks so much for the help

The solution is simple. Try this code like below:-

Your AppUser.cs model:-


  public class AppUser:IdentityUser  
    {
       ... 
    }

Your startup.cs file:-

services.AddIdentity<AppUser, IdentityRole>(options=> {
                options.Password.RequireDigit = false;
                ...
            })
                .AddEntityFrameworkStores<DataContext>()
                .AddDefaultTokenProviders();

Try exact same code as above.It will resolve your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM