Try Now
More in this section

Forums / Sitefinity SDK / Mass users enroll

Mass users enroll

2 posts, 0 answered
  1. Oleg
    Oleg avatar
    7 posts
    02 Mar 2009
    02 Feb 2011
    Link to this post
    We need to create customer's accounts from our ERP system (backend MS SQL database) in Sitefinity 4.
    I created role, "Customers" and now need to create user accounts within this role.
    Could you please advice how can I do this quickly?

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    25 Oct 2016
    02 Feb 2011
    Link to this post
    Hello Oleg,

    You can do this programmatically. Below is a sample code. First you have to create the user. Then you have to add it to your role.

    var userManager = UserManager.GetManager("Default");
    System.Web.Security.MembershipCreateStatus status;
    userManager.Provider.SuppressSecurityChecks = true;
    var user = userManager.CreateUser("user1", "user111@", "user1@test.com", "Question", "Answer", true, null, out status);
    user.FirstName = "FirstName";
    user.LastName = "LastName";
    RoleManager roleManager = RoleManager.GetManager();
    roleManager.Provider.SuppressSecurityChecks = true;
    var role = roleManager.GetRole("Customers");
    roleManager.AddUserToRole(user, role);

    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
2 posts, 0 answered