public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SeedDbData seedData) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); // Does not work with HTTPS //app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); // Ensure that we created the database try { using ( var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { serviceScope.ServiceProvider.GetService <ApplicationDbContext>().Database.Migrate(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } app.UseStaticFiles(); app.UseIdentity(); app.UseIdentityServer(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); await seedData.EnsureSeedDataAsync(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IAntiforgery antiforgery, SeedDbData seedData) { if (env.IsDevelopment()) { loggerFactory.AddSerilog(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true, ConfigFile = "config/webpack.config.js" }); // NOTE: For SPA swagger needs adding before MVC // Enable middleware to serve generated Swagger as a JSON endpoint app.UseSwagger(); // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.) app.UseSwaggerUi(); } else { app.UseResponseCompression(); // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859 try { using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { serviceScope.ServiceProvider.GetService <ApplicationDbContext>().Database.Migrate(); } } catch (Exception) { } } // Configure XSRF middleware, This pattern is for SPA style applications where XSRF token is added on Index page // load and passed back token on every subsequent async request app.Use(async(context, next) => { if (string.Equals(context.Request.Path.Value, "/", StringComparison.OrdinalIgnoreCase)) { var tokens = antiforgery.GetAndStoreTokens(context); context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken, new CookieOptions() { HttpOnly = false }); } await next.Invoke(); }); app.UseStaticFiles(); app.UseIdentity(); // // Facebook Auth // app.UseFacebookAuthentication(new FacebookOptions() // { // AppId = Configuration["Authentication:Facebook:AppId"], // AppSecret = Configuration["Authentication:Facebook:AppSecret"] // }); // // Google Auth // app.UseGoogleAuthentication(new GoogleOptions() // { // ClientId = Configuration["Authentication:Google:ClientId"], // ClientSecret = Configuration["Authentication:Google:ClientSecret"] // }); // // Twitter Auth // // https://apps.twitter.com/ // app.UseTwitterAuthentication(new TwitterOptions() // { // ConsumerKey = Configuration["Authentication:Twitter:ConsumerKey"], // ConsumerSecret = Configuration["Authentication:Twitter:ConsumerSecret"] // }); // // Microsoft Auth // // https://apps.dev.microsoft.com/?mkt=en-us#/appList // app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions() // { // ClientId = Configuration["Authentication:Microsoft:ClientId"], // ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"] // }); // // Note: Below social providers are supported through this open source library: // // https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers // // Github Auth // // https://github.com/settings/developers // app.UseGitHubAuthentication(new GitHubAuthenticationOptions // { // ClientId = Configuration["Authentication:Github:ClientId"], // ClientSecret = Configuration["Authentication:Github:ClientSecret"] // }); // app.UseLinkedInAuthentication(new LinkedInAuthenticationOptions // { // ClientId = Configuration["Authentication:LinkedIn:ClientId"], // ClientSecret = Configuration["Authentication:LinkedIn:ClientSecret"] // }); app.UseMvc(routes => { routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }); await seedData.EnsureSeedDataAsync(); }