// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string conn = Configuration.GetConnectionString("DefaultConnection"); if (conn.Contains("%CONTENTROOTPATH%")) { conn = conn.Replace("%CONTENTROOTPATH%", _contentRootPath); } DbConfig.ConfigureDb(services, conn); RepositoriesConfig.ConfigureRepositories(services); ServicesConfig.ConfigureServices(services); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.Configure <AuthTokenOptions>(Configuration.GetSection("Authorization:Jwt")); var authTokenOptions = services.BuildServiceProvider().GetService <IOptions <AuthTokenOptions> >().Value; services.AddIdentity <ApplicationUser, IdentityRole>(options => { options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(10); options.Lockout.MaxFailedAccessAttempts = 5; options.Password.RequireDigit = false; options.Password.RequireLowercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; }) .AddEntityFrameworkStores <SimContext>() .AddDefaultTokenProviders(); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(cfg => { cfg.RequireHttpsMetadata = false; cfg.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = authTokenOptions.Issuer, ValidateAudience = true, ValidAudience = authTokenOptions.Audience, ValidateLifetime = true, IssuerSigningKey = authTokenOptions.GetSymmetricSecurityKey(), ValidateIssuerSigningKey = true, ClockSkew = TimeSpan.Zero }; }); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
protected void Application_Start() { AntiForgeryConfig.SuppressIdentityHeuristicChecks = true; AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); FilterConfig.RegisterWebApiFilters(GlobalConfiguration.Configuration.Filters); BundleConfig.RegisterBundles(BundleTable.Bundles); DbConfig.ConfigureDb(); Bootstrapper.Initialize(GlobalConfiguration.Configuration); ModelBinders.Binders.Add(typeof(DataTableParamModel), new DataTableParamModelBinderAttribute()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var conn = Configuration.GetConnectionString("DefaultConnection"); if (conn.Contains("%CONTENTROOTPATH%")) { conn = conn.Replace("%CONTENTROOTPATH%", _contentRootPath); } DbConfig.ConfigureDb(services, conn); services.AddDefaultIdentity <User>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <DataContext>(); services.AddHttpContextAccessor(); services.AddRazorPages().AddRazorPagesOptions(options => { options.Conventions.AddAreaPageRoute("Identity", "/Account/Login", "/login"); options.Conventions.AddPageRoute("/Admin/Index", "/control"); options.Conventions.AddPageRoute("/ContentPage", "{*url}"); options.Conventions.AddPageRoute("/PageCategory", "/category/{url}"); options.Conventions.AuthorizeFolder("/Admin"); }); services.AddTransient <IPostService, PostService>(); services.AddTransient <ITeacherService, TeacherService>(); services.AddTransient <IVacancyService, VacancyService>(); services.AddTransient <IReviewService, ReviewService>(); services.AddTransient <IPageService, PageService>(); services.AddTransient <IPageCategoryService, PageCategoryService>(); services.AddTransient <IPhotoService, PhotoService>(); services.AddTransient <IApplicationService, ApplicationService>(); services.AddTransient <ITemplateImageService, TemplateImageService>(); services.AddTransient <IFileService, FileService>(); services.Configure <IdentityOptions>(options => { options.Password.RequireDigit = false; options.Password.RequiredLength = 5; options.Password.RequireLowercase = true; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; }); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { var conn = Configuration.GetConnectionString("DefaultConnection"); if (conn.Contains("%CONTENTROOTPATH%")) { conn = conn.Replace("%CONTENTROOTPATH%", _contentRootPath); } //ConnectionConfig.SetConnString(Configuration.GetConnectionString("DefaultConnection")); services.AddRazorPages().AddRazorPagesOptions(options => { options.Conventions.AddAreaPageRoute("Identity", "/Account/Login", "/login"); }); services.AddServerSideBlazor(); services .AddScoped <AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider <IdentityUser> >(); DbConfig.ConfigureDb(services, conn); RepositoriesConfig.ConfigureRepositories(services); ServicesConfig.ConfigureServices(services); services.AddDefaultIdentity <ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <DataContext>(); services.AddHttpContextAccessor(); // services.AddIdentity<ApplicationUser, IdentityRole>(options => // { // options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(10); // options.Lockout.MaxFailedAccessAttempts = 5; // options.Password.RequireDigit = false; // options.Password.RequireLowercase = false; // options.Password.RequireNonAlphanumeric = false; // options.Password.RequireUppercase = false; // }) // .AddEntityFrameworkStores<DataContext>() // .AddDefaultTokenProviders(); }
protected void Application_Start() { DbConfig.ConfigureDb(); }