SHARE
TWEET

Untitled

a guest Jul 18th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Create a class that implements IUserType:
  2.  
  3. [Serializable]
  4.     [DataContract(IsReference = true)]
  5.     public class ProvisioningUserType : Entity, IUserType {
  6.         [DataMember]
  7.         public string Alias { get; set; }
  8.  
  9.         [DataMember]
  10.         public string Name { get; set; }
  11.  
  12.         [DataMember]
  13.         public IEnumerable<string> Permissions { get; set; }
  14.     }
  15.    
  16.     //Create a user with the following code:
  17.  
  18.  var userService = ApplicationContext.Current.Services.UserService;
  19.    
  20.     var email = "youremailhere";
  21.     var date = DateTime.Now;
  22.     var userType = new ProvisioningUserType()
  23.     {
  24.         Alias = "admin",
  25.         Name = "Administrators",
  26.         CreateDate = date,
  27.     };
  28.     var user = userService.GetByEmail(email);
  29.     userService.SaveUserType(userType);
  30.     if (user == null) {
  31.         // Create a new user
  32.         var newUser = userService.CreateUserWithIdentity(email, email, userType);
  33.         newUser.RawPasswordValue = (Membership.Providers["UsersMembershipProvider"] as UsersMembershipProvider).HashPasswordForStorage("password"); ;
  34.         // Save the new user
  35.         userService.Save(newUser);
  36.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top