C# AddEntityFrameworkStores只能由从IdentityUser派生的用户调用<;TKey>;

C# AddEntityFrameworkStores只能由从IdentityUser派生的用户调用<;TKey>;,c#,asp.net,asp.net-2.0,C#,Asp.net,Asp.net 2.0,我正在尝试为我的web应用程序创建一些角色,但由于出现Tkey异常,它实际上无法工作 我很高兴你投赞成票,这样其他需要帮助的人可以看到更多 我不知道怎样才能修好它。我觉得我的Startup.cs有问题 无论我如何尝试添加DefaultIdentity和添加角色 Startup.cs-在这一行中我得到一个错误: services.AddDefaultIdentity<IdentityRole>().AddRoles<IdentityRole>().AddDefaultUI(

我正在尝试为我的web应用程序创建一些角色,但由于出现
Tkey异常
,它实际上无法工作

我很高兴你投赞成票,这样其他需要帮助的人可以看到更多

我不知道怎样才能修好它。我觉得我的Startup.cs有问题

无论我如何尝试添加
DefaultIdentity
和添加角色

Startup.cs-在这一行中我得到一个错误:

services.AddDefaultIdentity<IdentityRole>().AddRoles<IdentityRole>().AddDefaultUI().AddEntityFrameworkStores<VerwaltungsprogrammContext>();

我通过将身份验证切换到用户帐户身份验证来再次创建项目,从而修复了此问题:)

如果您像这样在Startup.cs中写入该行,是否也会发生错误

services.AddIdentity<ApplicationUser, IdentityRole>()
        .AddEntityFrameworkStores<VerwaltungsprogrammContext>();
services.AddIdentity()
.AddEntityFrameworkStores();

我现在发现我现在使用的问题是
IdentityUser
而不是
ApplicationUser
它现在看起来是这样的:
services.AddIdentity().AddEntityFrameworkStores().AddDefaultTokenProviders()非常感谢您的帮助!
    namespace Verwaltungsprogramm
    {
    public static class Seed
    {
    public static async Task CreateRoles(IServiceProvider serviceProvider, IConfiguration Configuration)
    {
        //adding customs roles
        var RoleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
        var UserManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
        string[] roleNames = { "Admin", "Manager", "Member" };
        IdentityResult roleResult;
        foreach (var roleName in roleNames)
        {
            // creating the roles and seeding them to the database
            var roleExist = await RoleManager.RoleExistsAsync(roleName);
            if (!roleExist)
            {
                roleResult = await RoleManager.CreateAsync(new IdentityRole(roleName));
            }
        }
        // creating a super user who could maintain the web app
        var poweruser = new ApplicationUser
        {
            UserName = Configuration.GetSection("AppSettings")["UserEmail"],
            Email = Configuration.GetSection("AppSettings")["UserEmail"]
        };
        string userPassword = Configuration.GetSection("AppSettings")["UserPassword"];
        var user = await UserManager.FindByEmailAsync(Configuration.GetSection("AppSettings")["UserEmail"]);
        if (user == null)
        {
            var createPowerUser = await UserManager.CreateAsync(poweruser, userPassword);
            if (createPowerUser.Succeeded)
            {
                // here we assign the new user the "Admin" role 
                await UserManager.AddToRoleAsync(poweruser, "Admin");
            }
        }
    }
}
}
services.AddIdentity<ApplicationUser, IdentityRole>()
        .AddEntityFrameworkStores<VerwaltungsprogrammContext>();