public void Configuration(IAppBuilder app) { AppLocalRootPath = HostingEnvironment.MapPath("~/"); var log4NetConfigFilePath = HostingEnvironment.MapPath("~/log4net.config"); if (AppLocalRootPath == null) { Console.WriteLine("Starting in self hosting mode"); AppLocalRootPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); log4NetConfigFilePath = Path.Combine(AppLocalRootPath, "log4net.config"); } var logConfigFileInfo = new FileInfo(log4NetConfigFilePath); if (logConfigFileInfo.Exists) { XmlConfigurator.ConfigureAndWatch(logConfigFileInfo); } else { XmlConfigurator.Configure(); } ConfigureBackend(app); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var identityConfiguration = new IdentityConfiguration(IdentityDatabaseContextFactory); var task = identityConfiguration.EnsureDefaultUsersAndRolesAsync(); ConfigureAuth(app); task.GetAwaiter().GetResult(); var properties = new AppProperties(app.Properties); var token = properties.OnAppDisposing; if (token != CancellationToken.None) { token.Register(() => { Storage?.Dispose(); AuthDatabase?.Dispose(); Container?.Dispose(); }); } }
private static void ProcessCommand(MyArguments arguments) { Check.DoRequireArgumentNotNull(arguments, nameof(arguments)); if (arguments.IsOperationResetAdmin) { CheckCommandLineArgument(!string.IsNullOrWhiteSpace(arguments.IdentityDatabasePath), "Identity database path is required."); CheckCommandLineArgument(!string.IsNullOrWhiteSpace(arguments.NewPassword), "New password is required."); var database = new LiteDatabase($"Filename={arguments.IdentityDatabasePath}; Password={arguments.DatabasePassword};"); var contextFactory = new IdentityDatabaseContextFactory(database); var identityConfig = new IdentityConfiguration(contextFactory); identityConfig.EnsureDefaultUsersAndRolesAsync().GetAwaiter().GetResult(); Console.WriteLine("Resetting admin password in {0} to {1}", arguments.IdentityDatabasePath, arguments.NewPassword); identityConfig.ResetPasswordAsync(IdentityConfiguration.AdminUserName, arguments.NewPassword) .GetAwaiter() .GetResult(); var userManager = ApplicationUserManager.CreateOutOfContext(contextFactory); var adminUser = userManager.FindByNameAsync(IdentityConfiguration.AdminUserName) .GetAwaiter().GetResult(); Console.WriteLine("Admin user locked: {0}; end date: {1}, has password: {2}", adminUser?.LockoutEnabled, adminUser?.LockoutEndDateUtc, adminUser?.HasPassword()); if (adminUser != null) { if (adminUser.LockoutEnabled) { Console.WriteLine("Unlocking admin"); userManager.ResetAccessFailedCountAsync(adminUser.Id); userManager.SetLockoutEnabledAsync(adminUser.Id, false); } } } else { throw new MyArgumentException($"Operation not recognized: '{arguments.Operation}'; nothing to do."); } }