简体   繁体   中英

Unable to login after seeding admin role and user while the data is in the database (postgresSQL)

What I want to do:<\/strong>

He can directly log in to the system and perform his assigned tasks(Create\/edit\/delete\/view user and other stuff).

    {
        public static void Seed(UserManager<IdentityUser> userManager,
                               RoleManager<IdentityRole> roleManager)
        {
            SeedRoles(roleManager);
            SeedUsers(userManager);
        }
        private static void SeedUsers(UserManager<IdentityUser> userManager)
        {
            if (userManager.FindByNameAsync("admin").Result == null)
            {
                var user = new IdentityUser
                {
                    UserName = "admin@gmail.com",
                    Email = "admin@gmail.com",
                };
                
                var result = userManager.CreateAsync(user, "ch@ba999OOH").Result;
                if (result.Succeeded) 
                {
                    userManager.AddToRoleAsync(user, "Admin").Wait();
                }  
            }
        }
        private static void SeedRoles( RoleManager<IdentityRole> roleManager)
        {
            if (!roleManager.RoleExistsAsync("Admin").Result)
            {
                var role = new IdentityRole
                {
                    Name = "Admin"
                };
               var result = roleManager.CreateAsync(role).Result;
            }
            if (!roleManager.RoleExistsAsync("Employee").Result)
            {
                var role = new IdentityRole
                {
                    Name = "Employee"
                };
                var result = roleManager.CreateAsync(role).Result;
            }
        }
    }

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