public void Configuration(IAppBuilder app) { log4net.Config.XmlConfigurator.Configure(); ILog logger = LogManager.GetLogger("Logger"); logger.Info("Application Started"); logger.Info("Configuring DI container"); IWindsorContainer container = new WindsorContainer(); ServiceLocator.Set(container); BootstrapConfig.Register(container, logger); logger.Info("Configuring HTTP Middleware"); app.MapSignalR(); app.UseMultitenancy(new MultitenancyNotifications <TenantDto> { TenantIdentifierNotFound = context => { throw new HttpException(404, "Tenant identifier must be provided"); }, TenantRecordNotFound = context => { context.Response.Redirect("/signup/tenant/"); return(Task.FromResult(0)); }, CreateTenantContext = (context, tenantRecord) => { ITenantContextFactory tenantContextFactory = ServiceLocator.Resolve <ITenantContextFactory>(); TenantContext tenantContext = tenantContextFactory.Create(tenantRecord.Id, tenantRecord.NameFriendly, tenantRecord.AuthClientId, tenantRecord.AuthAuthority); return(Task.FromResult(tenantContext)); } }); app.UsePerTenant((tenantContext, appBranch) => { appBranch.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); appBranch.UseCookieAuthentication(new CookieAuthenticationOptions { CookieName = $"OAuthCookie.{tenantContext.FriendlyName}" }); appBranch.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions { ClientId = tenantContext.AuthClientId, Authority = tenantContext.AuthAuthority, RedirectUri = $"http://localhost:2295/{tenantContext.FriendlyName}/", Notifications = new OpenIdConnectAuthenticationNotifications() { AuthenticationFailed = context => { context.HandleResponse(); throw context.Exception; } } }); appBranch.Use <AuthenticationChallangeMiddleware>(); appBranch.Use <AuthenticationAudienceCheckMiddleware>(tenantContext); appBranch.Use <AuthenticationClaimsAppenderMiddleware>(); }); logger.Info("Configuring MVC Pipeline"); AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier; logger.Info("Configuring Domain, DTO and Model Mapping"); MappingConfig.RegisterMapping(); Mapper.AddProfile(new Web.Models.Map()); app.OnDispose(() => { ServiceLocator.Resolve <ILog>().Info("Application Ended"); ServiceLocator.Release(); }); }
// 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, BasicSeedManager seedManager, MigrationManager migrationManager) { var stopwatch = Stopwatch.StartNew(); try { loggerFactory.AddSerilog(); Log.Logger().Information("Application is starting..."); Log.Logger().Information("Configuration:"); ConfigurationProvider.GetType().GetProperties().ToList().ForEach(prop => { Log.Logger().Information("[{name}] = '{value}'", prop.Name, prop.GetValue(ConfigurationProvider)); }); DateTimeContext.Initialize(ConfigurationProvider.TimeZone); Log.Logger().Information("Configure EF Mappings..."); MappingConfig.RegisterMappings(); Log.Logger().Information("Configure Jwt Bearer Authentication..."); app.ConfigJwtBearerMiddleware(); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Default}/{action=Index}/{id?}"); routes.MapRoute( name: "admin", template: "{*url}", defaults: new { controller = "Default", action = "Index" } ); }); //app.Use(async (context, next) => //{ // await next(); // if (context.Response.StatusCode == 404 && // !Path.HasExtension(context.Request.Path.Value) && // !context.Request.Path.Value.StartsWith("/api/")) // { // context.Request.Path = "/index.html"; // await next(); // } //}); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); migrationManager.ApplyMigrations(ConfigurationProvider); //seedManager.Seed(); } else { app.UseExceptionHandler("/error"); } } catch (Exception e) { Log.Logger().Error(e, "Application failed to start"); throw; } finally { stopwatch.Stop(); Log.Logger().Information("Startup time: {Seconds}s", stopwatch.Elapsed.Seconds); } }