using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System.IO; using Microsoft.AspNetCore.Identity; using APP.Identity; using APP.Models; using APP.Utils; using APP.Helper; using Microsoft.AspNetCore.Authentication.Cookies; using BWPMModels; namespace APP { public class Startup { [Obsolete] //public Startup(IConfiguration configuration) public Startup(Microsoft.AspNetCore.Hosting.IHostingEnvironment evm) { //Configuration = configuration; var builder = new ConfigurationBuilder() .SetBasePath(evm.ContentRootPath) .AddJsonFile("appsettings.json", true, true) .AddJsonFile($"appsettings.{evm.EnvironmentName}.json", true) .AddEnvironmentVariables(); Configuration = builder.Build(); AppSettings.Instance.SetConfiguration(Configuration); } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddIdentity().AddDefaultTokenProviders(); services.Configure(options => { // Password settings. options.Password.RequireDigit = true; options.Password.RequireLowercase = false; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = false; options.Password.RequiredLength = 8; // Lockout settings. options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 5; options.Lockout.AllowedForNewUsers = true; // User settings. options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+"; options.User.RequireUniqueEmail = true; }); services.ConfigureApplicationCookie(options => { // Cookie settings options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromMinutes(90); options.LoginPath = "/"; options.AccessDeniedPath = "/404"; options.SlidingExpiration = true; // options.Events = new MyCookieAuthenticationEvents(); }); services.AddTransient, UserStoreAppService>(); services.AddTransient, RoleAppService>(); services.AddScoped, PasswordHasherOverride>(); // services.AddScoped(); // services.AddScoped(); services.AddScoped, CustomClaimsPrincipal>(); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(); //services.AddControllersWithViews(); services.AddDistributedMemoryCache(); //This way ASP.NET Core will use a Memory Cache to store session variables services.AddSession(options => { options.IdleTimeout = TimeSpan.FromDays(1); // It depends on user requirements. options.Cookie.Name = ".My.Session"; // Give a cookie name for session which will be visible in request payloads. }); //services.ConfigureApplicationCookie(options => //{ // options.LoginPath = $"/account/login"; // options.LogoutPath = $"/account/logout"; // options.AccessDeniedPath = $"/account/accessDenied"; //}); //services.AddRazorPages(); //services.AddIdentity().AddDefaultTokenProviders(); //services.Configure(options => //{ // // Password settings. // options.Password.RequireDigit = true; // options.Password.RequireLowercase = false; // options.Password.RequireNonAlphanumeric = true; // options.Password.RequireUppercase = false; // options.Password.RequiredLength = 8; // // Lockout settings. // options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); // options.Lockout.MaxFailedAccessAttempts = 5; // options.Lockout.AllowedForNewUsers = true; // // User settings. // options.User.AllowedUserNameCharacters = // "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+"; // options.User.RequireUniqueEmail = true; //}); //services.ConfigureApplicationCookie(options => //{ // // Cookie settings // options.Cookie.HttpOnly = true; // options.ExpireTimeSpan = TimeSpan.FromMinutes(90); // options.LoginPath = "/"; // options.AccessDeniedPath = "/404"; // options.SlidingExpiration = true; // // options.Events = new MyCookieAuthenticationEvents(); //}); //services.AddTransient, UserStoreAppService>(); //services.AddTransient, RoleAppService>(); //services.AddScoped, PasswordHasherOverride>(); //services.AddScoped(); //services.AddScoped(); //services.AddScoped, CustomClaimsPrincipal>(); //services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(); } // 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(); } 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.UseSession(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); //app.UseEndpoints(endpoints => //{ // endpoints.MapControllerRoute( // name: "default", // pattern: "{controller=Employee}/{action=Login}/{id?}"); //}); //app.UseSession(); //if (env.IsDevelopment()) //{ // app.UseDeveloperExceptionPage(); //} //else //{ // app.UseExceptionHandler("/Home/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.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); if (Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), @"node_modules",@"@syncfusion"))) { if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", @"js", @"ej2"))) { Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", @"js", @"ej2")); File.Copy(Path.Combine(Directory.GetCurrentDirectory(), @"node_modules", @"@syncfusion", @"ej2-js-es5", @"scripts", @"ej2.min.js"), Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", @"js", @"ej2", @"ej2.min.js")); } if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", @"css", @"ej2"))) { Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", @"css", @"ej2")); File.Copy(Path.Combine(Directory.GetCurrentDirectory(), @"node_modules", @"@syncfusion", @"ej2-js-es5", @"styles", @"bootstrap.css"), Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", @"css", @"ej2", @"bootstrap.css")); File.Copy(Path.Combine(Directory.GetCurrentDirectory(), @"node_modules", @"@syncfusion", @"ej2-js-es5", @"styles", @"bootstrap4.css"), Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", @"css", @"ej2", @"bootstrap4.css")); File.Copy(Path.Combine(Directory.GetCurrentDirectory(), @"node_modules", @"@syncfusion", @"ej2-js-es5", @"styles", @"material.css"), Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", @"css", @"ej2", @"material.css")); File.Copy(Path.Combine(Directory.GetCurrentDirectory(), @"node_modules", @"@syncfusion", @"ej2-js-es5", @"styles", @"highcontrast.css"), Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", @"css", @"ej2", @"highcontrast.css")); File.Copy(Path.Combine(Directory.GetCurrentDirectory(), @"node_modules", @"@syncfusion", @"ej2-js-es5", @"styles", @"fabric.css"), Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", @"css", @"ej2", @"fabric.css")); } } } } }