Create Users, assign roles with datareader? - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Create Users, assign roles with datareader?

  • Create Users, assign roles with datareader?
  • The first iteration works fine and the new user is created. The second time through the var user is set to null.  Any thoughts? Thanks in advance.
    while (reader.Read())
                
                    var userManager = UserManager.GetManager("Default");
                    System.Web.Security.MembershipCreateStatus status;
                    userManager.Provider.SuppressSecurityChecks = true;
                    var eeid = reader["eeid"];
     
                    var user = userManager.CreateUser(reader["eeid"].ToString(), reader["dob"].ToString(), "email@test.com", "Question1", "Answer1", true, null, out status);
                    user.FirstName = reader["fname"].ToString();
                    user.LastName = reader["lname"].ToString();
     
                    user.IsBackendUser = false;
     
                    userManager.SaveChanges();
     
                    RoleManager roleManager = RoleManager.GetManager();
     
                    roleManager.Provider.SuppressSecurityChecks = true;
     
                    var role = roleManager.GetRole("Union");
     
                    roleManager.AddUserToRole(user, role);
     
                    roleManager.SaveChanges();
     
     
                
     
                reader.Close();
                cmd.Connection.Close();

  • Hello Brent,

    If you run the API the user will be created, but then you will have to change username, e-mail to execute it again since there is already such user.

    Regards,
    Stanislav Velikov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>