ASP.NET标识创建多个用户

时间:2014-02-21 13:34:18

标签: c# asp.net asp.net-identity

我正在运行此代码来为我的数据库设定种子,但数据没有被写入。单独添加用户(在ForEach循环之外)时,它可以正常工作。是否有任何理由不起作用

List<String> usersList = GetAllUsers();

        foreach (string s in usersList)
        {
            var newUser = new ApplicationUser();
            newUser.UserName = s;
            newUser.Email = s;
            var userResult = UserManager.Create(newUser, "greenford");

            //Add User Role Applicant
            if (userResult.Succeeded)
            {
                var result = UserManager.AddToRole(newUser.Id, "Applicant");
            }
        }

0 个答案:

没有答案