// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { _applicationBuilder = app; loggerFactory.AddFile("Logs/log-{Date}.txt", LogLevel.Warning); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }); // app.UseRequestLocalization(); app.Use(async(context, next) => { await next(); //redirect to login if (context.Response.StatusCode == 401 && !context.IsJsonRequest()) { context.Response.Redirect(ControllerExtensions.RedirectLogin(context.Request.GetDisplayUrl())); } }); app.UseResponseCaching(); app.UseResponseCompression(); app.UseStaticFiles(); if (!env.IsDevelopment()) { app.UseSpaStaticFiles(); } app.UseAuthentication(); #if DEBUG app.UseSwagger(); app.UseSwaggerUi3(); #endif app.UseMvc(); app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp"; }); var databaseSetupTask = SetupDatabase(loggerFactory, app.ApplicationServices); if (!databaseSetupTask.IsCompleted) { databaseSetupTask.AsTask().Wait(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddFile("Logs/log-{Date}.txt", LogLevel.Warning); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }); // app.UseRequestLocalization(); app.Use(async(context, next) => { await next(); //redirect to login if (context.Response.StatusCode == 401 && !context.IsJsonRequest()) { context.Response.Redirect(ControllerExtensions.RedirectLogin(context.Request.GetDisplayUrl())); } if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value) && !context.Request.Path.Value.StartsWith("/api/")) { // var requestCulture = context.Features.Get<IRequestCultureFeature>().RequestCulture; // context.Request.Path = $"/{requestCulture.Culture.TwoLetterISOLanguageName}/index.html"; context.Request.Path = "/index.html"; await next(); } }); app.UseStaticFiles(); // app.UseResponseCaching(); app.UseAuthentication(); app.UseSentinel(); app.UseMvc(); ConfigureDatabase(app.ApplicationServices, loggerFactory.CreateLogger("database")); #if DEBUG using (var scope = app.ApplicationServices.CreateScope()) { var dbConnection = scope.ServiceProvider.GetService <IDbConnection>(); var roleManager = scope.ServiceProvider.GetService <RoleManager <LinqToDB.Identity.IdentityRole <int> > >(); var missingRoles = new[] { "admin", "hr", "hradmin" }.Except(roleManager.Roles.Select(role => role.Name)); foreach (var missingRole in missingRoles) { roleManager.CreateAsync(new LinqToDB.Identity.IdentityRole <int>(missingRole)).Wait(); } //to configure db look at ServiceFixture.SetupSchema if (!dbConnection.Users.Any()) { var userService = scope.ServiceProvider.GetService <UserService>(); var identityUser = new IdentityUser { UserName = "******", ResetPassword = true }; userService.CreateAsync(identityUser, "password").Wait(); userService.AddToRoleAsync(identityUser, "admin").Wait(); } } #endif }