public static DAL.User CreateUser(DAL.User user) { try { using (TransactionScope ts = new TransactionScope()) { using (BLL.UserManager um = new BLL.UserManager()) { if (user.Password == null || user.Password.Trim() == "") user.Password = WebSecurity.Membership.GeneratePassword(8, 0); WebSecurity.MembershipUser membershipUser = WebSecurity.Membership.CreateUser(user.UserName, user.Password, user.Email); Guid ProviderKey = (Guid)membershipUser.ProviderUserKey; user.MembershipProviderKey = ProviderKey; if (user.Role.Trim() != "") { string[] roles = user.Role.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (roles.Length > 0) AddUserToRoles(user.UserName, roles); } um.CreateUser(user); } ts.Complete(); } return user; } catch (WebSecurity.MembershipCreateUserException) { throw new Exceptions.UserException("User account creation failed."); } catch (WebSecurity.MembershipPasswordException) { throw new Exceptions.UserException("Please provide a valid password."); } catch (Exception) { throw new Exceptions.UserException("User account creation failed."); } }