public SimpleMembershipInitializer() { lock (_initializerLock) { logger.Debug("Initializing membership database"); Database.SetInitializer<UsersContext>(null); try { using (var context = new UsersContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); logger.Debug("Created new membership database"); } } WebSecurity.InitializeDatabaseConnection("AccountConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); logger.Debug("Membership database connection initialized"); if (!Roles.RoleExists("Guides")) { Roles.CreateRole("Guides"); WebSecurity.CreateUserAndAccount("admin", "password"); Roles.AddUserToRole("admin", "Guides"); logger.Debug("Created default admin account"); } } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } } }
protected virtual void Dispose(bool disposing) { if (disposing) { if (usersContext != null) { usersContext.Dispose(); usersContext = null; } if (textContext != null) { textContext.Dispose(); textContext = null; } } }