public TeamsInMemoryDbRepository(DbSeeder <Team> seeder) : base(seeder) { }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } //app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseSession(); app.UseResponseCompression(); app.UseMvc(routes => { routes.MapRoute( name: "homeAdmin", template: "{area:exists}/{controller=home}/{action=Index}/{id?}" ); routes.MapRoute( name: "cardAdmin", template: "{area:exists}/{controller=card}/{action=Index}/{id?}" ); routes.MapRoute( name: "NopCardAdmin", template: "{area:exists}/{controller=giao-dich}/{action=Index}/{id?}" ); routes.MapRoute( name: "slideAdmin", template: "{area:exists}/{controller=slide}/{action=Index}/{id?}" ); routes.MapRoute( name: "feedbackAdmin", template: "{area:exists}/{controller=feedback}/{action=Index}/{id?}" ); routes.MapRoute( name: "pageAdmin", template: "{area:exists}/{controller=page}/{action=Index}/{id?}" ); routes.MapRoute( name: "postAdmin", template: "{area:exists}/{controller=post}/{action=Index}/{id?}" ); routes.MapRoute( name: "tagsAdmin", template: "{area:exists}/{controller=tags}/{action=Index}/{id?}" ); routes.MapRoute( name: "contactAdmin", template: "{area:exists}/{controller=contact}/{action=Index}/{id?}" ); routes.MapRoute( name: "accountAdmin", template: "{area:exists}/{controller=account}/{action=Index}/{id?}" ); routes.MapRoute( name: "nopthe", template: "/nap-the.html", defaults: new { controller = "Card", action = "Index" } ); routes.MapRoute( name: "post", template: "/khuyen-mai.html", defaults: new { controller = "Post", action = "Index" } ); routes.MapRoute( name: "post-detail", template: "/khuyen-mai/{metaname}/{id}", defaults: new { controller = "Post", action = "Detail" } ); routes.MapRoute( name: "lien-he", template: "/lien-he.html", defaults: new { controller = "Page", action = "ContactPage" } ); routes.MapRoute( name: "bang-gia", template: "/bang-gia.html", defaults: new { controller = "Page", action = "BangGia" } ); routes.MapRoute( name: "NopCard", template: "/giao-dich/{userId}", defaults: new { controller = "UserAccount", action = "LichSuNopCard" } ); routes.MapRoute( name: "NapThe", template: "/giao-dich/nap-tien", defaults: new { controller = "UserAccount", action = "NapTien" } ); routes.MapRoute( name: "XacThuc", template: "UserAccount/ConfirmEmail/{userid?}/{token?}", defaults: new { controller = "UserAccount", action = "ConfirmEmail" } ); routes.MapRoute( name: "default", template: "{controller=Card}/{action=Index}/{id?}"); }); WebTheCaoDbContext.CreateAdminAccount(app.ApplicationServices, Configuration).Wait(); using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetRequiredService <WebTheCaoDbContext>(); var roleManager = serviceScope.ServiceProvider.GetService <RoleManager <IdentityRole> >(); var userManager = serviceScope.ServiceProvider.GetService <UserManager <ApplicationUser> >(); dbContext.Database.Migrate(); DbSeeder.Seed(dbContext, roleManager, userManager); } }
// 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, DbSeeder dbSeeder) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); } else { app.UseExceptionHandler("/Home/Error"); } app.UseDefaultFiles(); app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = context => { // Disable caching for all static files. context.Context.Response.Headers["Cache-Control"] = Configuration["StaticFiles:Headers:Cache-Control"]; context.Context.Response.Headers["Pragma"] = Configuration["StaticFiles:Headers:Pragma"]; context.Context.Response.Headers["Expires"] = Configuration["StaticFiles:Headers:Expires"]; } }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Ang}/{id?}"); routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }); Mapper.Initialize(cfg => { cfg.CreateMap <Item, ItemViewModel>(); cfg.CreateMap <ItemViewModel, Item>(); }); try { dbSeeder.SeedAsync().Wait(); } catch (AggregateException e) { throw new Exception(e.ToString()); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); // Register the Swagger generator and the Swagger UI middlewares app.UseSwaggerUi3WithApiExplorer(settings => { settings.GeneratorSettings.DefaultPropertyNameHandling = PropertyNameHandling.CamelCase; }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}" ); routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" } ); }); //MapSpaFallbackRoute //app.MapWhen(r => !r.Request.Path.Value.StartsWith("/swagger"), builder => //{ // builder.UseMvc(routes => // { // routes.MapSpaFallbackRoute( // name: "spa-fallback", // defaults: new { controller = "Home", action = "Index" } // ); // }); //}); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); // Create a service scope to get an ApplicationDbContext instance using DI using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetService <ApplicationDbContext>(); // Create the Db if it doesn't exist and applies any pending migration. dbContext.Database.Migrate(); // Seed the Db. DbSeeder.Seed(dbContext); } }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); DbSeeder.Seed(); }
// 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, DbSeeder dbSeeder) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // Configure a rewrite rule to auto-lookup for standard default files such as index.html. app.UseDefaultFiles(); // Serve static files (html, css, js, images & more). See also the following URL: // https://docs.asp.net/en/latest/fundamentals/static-files.html for further reference. app.UseStaticFiles(new StaticFileOptions() { OnPrepareResponse = (context) => { // Disable caching for all static files. context.Context.Response.Headers["Cache-Control"] = Configuration["StaticFiles:Headers:Cache-Control"]; context.Context.Response.Headers["Pragma"] = Configuration["StaticFiles:Headers:Pragma"]; context.Context.Response.Headers["Expires"] = Configuration["StaticFiles:Headers:Expires"]; } }); // Add MVC to the pipeline app.UseMvc(); // TinyMapper binding configuration TinyMapper.Bind<Item, ItemViewModel>(); // Seed the Database (if needed) try { dbSeeder.SeedAsync().Wait(); } catch (AggregateException e) { throw new Exception(e.ToString()); } }
// 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, DbSeeder dbSeeder) { //loggerFactory.AddConsole(Configuration.GetSection("Logging")); //loggerFactory.AddDebug(); app.UseDefaultFiles(); app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = (context) => { // Disable caching for all static files. context.Context.Response.Headers["Cache-Control"] = Configuration["StaticFiles:Headers:Cache-Control"]; context.Context.Response.Headers["Pragma"] = Configuration["StaticFiles:Headers:Pragma"]; context.Context.Response.Headers["Expires"] = Configuration["StaticFiles:Headers:Expires"]; } }); app.UseJwtProvider(); app.UseIdentity(); // Add external authentication middleware below. app.UseFacebookAuthentication(new FacebookOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, AppId = Configuration["Authentication:Facebook:AppId"], AppSecret = Configuration["Authentication:Facebook:AppSecret"], CallbackPath = "/signin-facebook", Scope = { "email" } }); app.UseGoogleAuthentication(new GoogleOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, ClientId = Configuration["Authentication:Google:ClientId"], ClientSecret = Configuration["Authentication:Google:ClientSecret"], CallbackPath = "/signin-google", Scope = { "email" } }); app.UseTwitterAuthentication(new TwitterOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, ConsumerKey = Configuration["Authentication:Twitter:ConsumerKey"], ConsumerSecret = Configuration["Authentication:Twitter:ConsumerSecret"], CallbackPath = "/signin-twitter" }); // Add OpenIddict middleware // Note: UseOpenIddict() must be registered after app.UseIdentity() and the external social providers. app.UseOpenIddict(); // Add the Jwt Bearer Header Authentication to validate Tokens app.UseJwtBearerAuthentication(new JwtBearerOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, RequireHttpsMetadata = false, Authority = Configuration["Authentication:OpenIddict:Authority"], TokenValidationParameters = new TokenValidationParameters() { ValidateIssuer = false, ValidateAudience = false } }); app.UseMvc(); // TinyMapper binding configuration TinyMapper.Bind <Item, ItemViewModel>(); // Seed the Database (if needed) try { dbSeeder.SeedAsync().Wait(); } catch (AggregateException e) { throw new Exception(e.ToString()); } }
// 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, DbSeeder dbSeeder) { //bu metodlda requestlerin nasıl karşılanacağına dair yazılan kodlardır. loggerFactory.AddConsole(Configuration.GetSection("Logging")); //loglamanın nasıl yapılacağını bildirir loggerFactory.AddDebug(); //hem console hem de debug klasörüneloglama yapılması gerektiği yazılmış dbSeeder.SeedAsync().Wait(); app.UseMvc(); //yüklenmiş olan paketler .csproj dosyasına kaydedilir odosyaya ise projeye sağ tık yapıp edi derseniz gidebilirsiniz }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); #if DEBUG app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); #endif } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(new StaticFileOptions() { OnPrepareResponse = (context) => { // Disable caching for all static files. context.Context.Response.Headers["Cache-Control"] = Configuration["StaticFiles:Headers:Cache-Control"]; context.Context.Response.Headers["Pragma"] = Configuration["StaticFiles:Headers:Pragma"]; context.Context.Response.Headers["Expires"] = Configuration["StaticFiles:Headers:Expires"]; } }); // Add the AuthenticationMiddleware to the pipeline app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }); /* Obsolete code: replaced on 2017/12/06 (see Program.cs file) * ref.: https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/#move-database-initialization-code */ // Create a service scope to get an ApplicationDbContext instance using DI using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetService <ApplicationDbContext>(); var roleManager = serviceScope.ServiceProvider.GetService <RoleManager <IdentityRole> >(); var userManager = serviceScope.ServiceProvider.GetService <UserManager <ApplicationUser> >(); // Create the Db if it doesn't exist and applies any pending migration. dbContext.Database.Migrate(); DbSeeder.Seed(dbContext, roleManager, userManager); } }
private void MainForm_Load(object sender, EventArgs e) { DbSeeder.SeedAll(this._context); FillTreeView(); }
public Form1() { context = new MyContext(); DbSeeder.SeedAll(context); InitializeComponent(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DbSeeder customersDbSeeder, IAntiforgery antiforgery) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } // This would need to be locked down as needed (very open right now) app.UseCors("AllowAllPolicy"); app.UseStaticFiles(); // Enable middleware to serve generated Swagger as a JSON endpoint app.UseSwagger(); // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.) // Visit http://localhost:5000/swagger app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); // Manually handle setting XSRF cookie. Needed because HttpOnly // has to be set to false so that Angular is able to read/access the cookie. app.Use((context, next) => { string path = context.Request.Path.Value; if (path != null && !path.ToLower().Contains("/api")) { var tokens = antiforgery.GetAndStoreTokens(context); context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken, new CookieOptions { HttpOnly = false } ); } return(next()); }); // For 3.0 app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action}/{id?}"); // Handle redirecting client-side routes to Customers/Index route endpoints.MapFallbackToController("Index", "Home"); }); customersDbSeeder.SeedAsync(app.ApplicationServices).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, DbSeeder dbSeeder, UserManager <ApplicationUser> userManager, TokenHelper tokenHelper, APIDbContext db) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors("any"); //在当前路径中开启默认文件映射 app.UseDefaultFiles(); //启用给定选项的静态文件服务。 app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = (context) => { context.Context.Response.Headers["Cache-Control"] = Configuration["StaticFiles:Headers:Cache-Control"]; context.Context.Response.Headers["Pragma"] = Configuration["StaticFiles:Headers:Pragma"]; context.Context.Response.Headers["Expires"] = Configuration["StaticFiles:Headers:Expires"]; } }); //将中间件添加到请求管道中 app.UseJWTMiddleware(); app.UseAuthentication(); app.UseMvc(); ////生成数据库执行此方法 //try //{ // dbSeeder.SeedAsync().Wait(); //} ////在应用程序执行期间响应一个或多个错误 //catch (AggregateException e) //{ // throw new Exception(e.InnerException.ToString()); //} }
// 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, DbSeeder dbSeeder) { app.UseDeveloperExceptionPage(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); dbSeeder.SeedAsync().Wait(); app.UseMvc(); }
// 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, DbSeeder dbSeeder) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // Configure a rewrite rule to auto-lookup for standard default files such as index.html. app.UseDefaultFiles(); // Serve static files (html, css, js, images & more). See also the following URL: // https://docs.asp.net/en/latest/fundamentals/static-files.html for further reference. app.UseStaticFiles(new StaticFileOptions() { OnPrepareResponse = (context) => { // Disable caching for all static files. context.Context.Response.Headers["Cache-Control"] = Configuration["StaticFiles:Headers:Cache-Control"]; context.Context.Response.Headers["Pragma"] = Configuration["StaticFiles:Headers:Pragma"]; context.Context.Response.Headers["Expires"] = Configuration["StaticFiles:Headers:Expires"]; } }); // Add a custom Jwt Provider to generate Tokens app.UseJwtProvider(); // Add the Jwt Bearer Header Authentication to validate Tokens app.UseJwtBearerAuthentication(new JwtBearerOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, RequireHttpsMetadata = false, TokenValidationParameters = new TokenValidationParameters() { IssuerSigningKey = JwtProvider.SecurityKey, ValidateIssuerSigningKey = true, ValidIssuer = JwtProvider.Issuer, ValidateIssuer = false, ValidateAudience = false } }); // Add MVC to the pipeline app.UseMvc(); // TinyMapper binding configuration TinyMapper.Bind <Item, ItemViewModel>(); try { dbSeeder.SeedAsync().Wait(); } catch (AggregateException e) { throw new Exception(e.ToString()); } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity <Owner>().HasData(DbSeeder.GenerateOwners().ToArray()); modelBuilder.Entity <Card>().HasData(DbSeeder.GenerateCards().ToArray()); }
// 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, DbSeeder dbSeeder) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // Configure a rewrite rule to auto-lookup for standard default files such as index.html. app.UseDefaultFiles(); // Serve static files (html, css, js, images & more). See also the following URL: // https://docs.asp.net/en/latest/fundamentals/static-files.html for further reference. app.UseStaticFiles(new StaticFileOptions() { OnPrepareResponse = (context) => { // Disable caching for all static files. context.Context.Response.Headers["Cache-Control"] = Configuration["StaticFiles:Headers:Cache-Control"]; context.Context.Response.Headers["Pragma"] = Configuration["StaticFiles:Headers:Pragma"]; context.Context.Response.Headers["Expires"] = Configuration["StaticFiles:Headers:Expires"]; } }); // Add a custom Jwt Provider to generate Tokens // app.UseJwtProvider(); // Add the AspNetCore.Identity middleware (required for external auth providers) // IMPORTANT: This must be placed *BEFORE* OpenIddict and any external provider's middleware app.UseIdentity(); // Add external authentication middleware below. // To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseFacebookAuthentication(new FacebookOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, AppId = Configuration["Authentication:Facebook:AppId"], AppSecret = Configuration["Authentication:Facebook:AppSecret"], CallbackPath = "/signin-facebook", Scope = { "email" } }); app.UseGoogleAuthentication(new GoogleOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, ClientId = Configuration["Authentication:Google:ClientId"], ClientSecret = Configuration["Authentication:Google:ClientSecret"], CallbackPath = "/signin-google", Scope = { "email" } }); app.UseTwitterAuthentication(new TwitterOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, ConsumerKey = Configuration["Authentication:Twitter:ConsumerKey"], ConsumerSecret = Configuration["Authentication:Twitter:ConsumerSecret"], CallbackPath = "/signin-twitter" }); // Add OpenIddict middleware // Note: UseOpenIddict() must be registered after app.UseIdentity() and the external social providers. app.UseOpenIddict(); // Add the Jwt Bearer Header Authentication to validate Tokens app.UseJwtBearerAuthentication(new JwtBearerOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, RequireHttpsMetadata = false, Authority = Configuration["Authentication:OpenIddict:Authority"], TokenValidationParameters = new TokenValidationParameters() { //IssuerSigningKey = JwtProvider.SecurityKey, //ValidateIssuerSigningKey = true, //ValidIssuer = JwtProvider.Issuer, ValidateIssuer = false, ValidateAudience = false } }); // Add MVC to the pipeline app.UseMvc(); // TinyMapper binding configuration TinyMapper.Bind <Item, ItemViewModel>(); // Seed the Database (if needed) try { dbSeeder.SeedAsync().Wait(); } catch (AggregateException e) { throw new Exception(e.ToString()); } }
private static void EnsureDataStorageIsReady(AppDbContext appDbContext) { DbSeeder.Seed(appDbContext); }
// 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, DbSeeder dbSeeder) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseDefaultFiles(); app.UseStaticFiles(); //add our JwtProvider that we created app.UseJwtProvider(); //add the built in authentication app.UseJwtBearerAuthentication(new JwtBearerOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, RequireHttpsMetadata = false, TokenValidationParameters = new TokenValidationParameters() { IssuerSigningKey = JwtProvider.SecurityKey, ValidIssuer = JwtProvider.Issuer, ValidateIssuerSigningKey = true, ValidateIssuer = false, ValidateAudience = false } }); //add facebook authentication app.UseFacebookAuthentication(new FacebookOptions() { AppId = Configuration["Authentication:Facebook:AppId"], AppSecret = Configuration["Authentication:Facebook:AppSecret"] }); app.UseMvc(); try { dbSeeder.SeedAsync().Wait(); } catch (AggregateException e) { throw new Exception(e.ToString()); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); } else { app.UseExceptionHandler("/Home/Error"); } //app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions() { OnPrepareResponse = (context) => { // Disable caching for all static files. context.Context.Response.Headers["Cache-Control"] = Configuration["StaticFiles:Headers:Cache-Control"]; context.Context.Response.Headers["Pragma"] = Configuration["StaticFiles:Headers:Pragma"]; context.Context.Response.Headers["Expires"] = Configuration["StaticFiles:Headers:Expires"]; } }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }); // Create a service scope to get an ApplicationDbContext instance // using DI using (var serviceScope = app .ApplicationServices .GetRequiredService <IServiceScopeFactory>() .CreateScope()) { var dbContext = serviceScope .ServiceProvider .GetService <ApplicationDbContext>(); //provide our DbSeeder class with a UserManager and a //RoleManager, as they are the required Microsoft.AspNetCore. //Identity handler classes to properly work with users and roles. var roleManager = serviceScope .ServiceProvider .GetService <RoleManager <IdentityRole> >(); var userManager = serviceScope .ServiceProvider .GetService <UserManager <ApplicationUser> >(); // Create the Db if it doesn't exist and applies // any pending migration. dbContext.Database.Migrate(); // Seed the Db. DbSeeder.Seed(dbContext, roleManager, userManager); } // Add the AuthenticationMiddleware to the pipeline app.UseAuthentication(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); using (var scope = app.ApplicationServices.CreateScope()) { //initialize & seed database using (var dbContext = scope.ServiceProvider.GetService <ClientIntegratorDbContext>()) { ClientIntegratorDbContext = dbContext; var connectionString = Configuration.GetConnectionString("ClientIntegratorDb"); if (connectionString != "InMemory") { //initialize & migrate to latest version dbContext.Database.Migrate(); } var roleManager = scope.ServiceProvider.GetService <RoleManager <PortalRole> >(); var userManager = scope.ServiceProvider.GetService <UserManager <PortalUser> >(); var userStore = scope.ServiceProvider.GetService <IUserStore <PortalUser> >(); if (!userManager.SupportsUserEmail) { throw new NotSupportedException("The UI requires a user store with email support."); } IUserEmailStore <PortalUser> emailStore = (IUserEmailStore <PortalUser>)userStore; if (!env.IsProduction()) { DbSeeder.Seed(dbContext, emailStore, userStore, userManager, roleManager, Configuration).Wait(); } else { DbSeeder.SeedProduction(dbContext, emailStore, userStore, userManager, roleManager, Configuration).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, DbSeeder dbSeeder) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); //app.UseApplicationInsightsRequestTelemetry(); //app.UseApplicationInsightsExceptionTelemetry(); // Configure a rewrite rule to auto-lookup for standard default files such as index.html. app.UseDefaultFiles(); // Serve static files (html, css, js, images & more). See also the following URL: // https://docs.asp.net/en/latest/fundamentals/static-files.html for further reference. app.UseStaticFiles(new StaticFileOptions() { OnPrepareResponse = (context) => { // Disable caching for all static files. context.Context.Response.Headers["Cache-Control"] = Configuration["StaticFiles:Headers:Cache-Control"]; context.Context.Response.Headers["Pragma"] = Configuration["StaticFiles:Headers:Pragma"]; context.Context.Response.Headers["Expires"] = Configuration["StaticFiles:Headers:Expires"]; } }); //// Add a custom Jwt Provider to generate Tokens //app.UseJwtProvider(); // Add the AspNetCore.Identity middleware (required for external auth providers) // IMPORTANT: This must be placed *BEFORE* OpenIddict and any external provider's middleware app.UseIdentity(); // Add external authentication middleware below. // To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseFacebookAuthentication(new FacebookOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, AppId = Configuration["FacebookAppId"], AppSecret = Configuration["FacebookAppSecret"], CallbackPath = "/signin-facebook", Scope = { "email" } }); app.UseGoogleAuthentication(new GoogleOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, ClientId = Configuration["GoogleClientId"], ClientSecret = Configuration["GoogleClientSecret"], CallbackPath = "/signin-google", Scope = { "email" } }); app.UseTwitterAuthentication(new TwitterOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, ConsumerKey = Configuration["TwitterConsumerKey"], ConsumerSecret = Configuration["TwitterConsumerSecret"], CallbackPath = "/signin-twitter" }); // Add OpenIddict middleware // Note: UseOpenIddict() must be registered after app.UseIdentity() and the external social providers. app.UseOpenIddict(); // Add the Jwt Bearer Header Authentication to validate Tokens app.UseJwtBearerAuthentication(new JwtBearerOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, RequireHttpsMetadata = false, Authority = Configuration["Authentication:OpenIddict:Authority"], TokenValidationParameters = new TokenValidationParameters() { //IssuerSigningKey = JwtProvider.SecurityKey, //ValidateIssuerSigningKey = true, //ValidIssuer = JwtProvider.Issuer, ValidateIssuer = false, ValidateAudience = false } }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); // Seed the Database (if needed) try { dbSeeder.SeedAsync().Wait(); } catch (AggregateException e) { throw new Exception(e.ToString()); } Mapper.Initialize(cfg => { var articleClientModelMap = cfg.CreateMap <Article, ArticleViewModel>() .ForMember(dest => dest.EntityRelationships, source => source.MapFrom(x => x.Entity.EntityRelationships)) //.ForMember(dest => dest.EntityRelationships., opt => opt.Ignore()) //ForMember(dest => dest.Id, source => source.MapFrom(x => x.ClientId)) .ReverseMap(); cfg.CreateMap <EntityRelationship, EntityRelationshipDTO>() .ForMember(dest => dest.Entity1Name, source => source.MapFrom(x => x.Entity1.Name)) .ForMember(dest => dest.Entity2Name, source => source.MapFrom(x => x.Entity2.Name)) .ForMember(dest => dest.RelationshipDescription, source => source.MapFrom(x => x.Relationship.Description)) .ForMember(dest => dest.RelationshipId, source => source.MapFrom(x => x.Relationship.Id)).ReverseMap(); //cfg.CreateMap<FlatEntity, Entity>().ReverseMap(); cfg.CreateMap <Relationship, RelationshipDTO>().ReverseMap(); cfg.CreateMap <Entity, EntityDTO>().ReverseMap(); cfg.CreateMap <Story, StoryViewModel>().ReverseMap(); }); //ItemViewModel ivm = Mapper.Map<ItemViewModel>(Article); //AutoMapper.Bind<Article, ItemViewModel>(); }
public BanServiceTests() { this.db = DbGenerator.GetDbContext(); DbSeeder.SeedNormalUsers(this.db); this.banService = new BanService(this.db); }