More in this section
Forums / Sitefinity SDK / Create Users, assign roles with datareader?

Create Users, assign roles with datareader?

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Brent Holliman
    Brent Holliman avatar
    1 posts
    14 May 2004
    26 Oct 2011
    Link to this post
    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(), "", "Question1", "Answer1", true, null, out status);
                    user.FirstName = reader["fname"].ToString();
                    user.LastName = reader["lname"].ToString();
                    user.IsBackendUser = false;
                    RoleManager roleManager = RoleManager.GetManager();
                    roleManager.Provider.SuppressSecurityChecks = true;
                    var role = roleManager.GetRole("Union");
                    roleManager.AddUserToRole(user, role);

  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    18 Sep 2017
    28 Oct 2011
    Link to this post
    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.

    Stanislav Velikov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

2 posts, 0 answered