Mvc Core Session Kontrolü için Startup Dosyası Yapılandırması

Mvc Core Session Kontrolü için Starup Dosyası Yapılandırmam

public class Startup {
private IConfiguration Configuration;

public Startup (IConfiguration configuration) {
Configuration = configuration;
}

public void ConfigureServices (IServiceCollection services) {

services.AddDbContext<MainContext> (options =>
options.UseSqlServer (Configuration.GetConnectionString (“DefaultConnection”)));

services.AddDbContext<UserContext> (options =>
options.UseSqlServer (Configuration.GetConnectionString (“UserConnection”)));

services.AddIdentity<AppUser, IdentityRole> ()
.AddEntityFrameworkStores<UserContext> ()
.AddDefaultTokenProviders ();

services.Configure<IdentityOptions> (options => {

options.Lockout.MaxFailedAccessAttempts = 10;
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromHours (3);
options.Password.RequireDigit = true;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequiredUniqueChars = 0;
options.Password.RequireLowercase = false;
options.Password.RequireUppercase = true;
options.Password.RequiredLength = 8;
});

services.Configure<SecurityStampValidatorOptions> (options => options.ValidationInterval = TimeSpan.FromHours (3));
services.AddAuthentication ()
.Services.ConfigureApplicationCookie (options => {
options.SlidingExpiration = true;
options.ExpireTimeSpan = TimeSpan.FromHours (3);
options.LoginPath = “/security/login”;
options.LogoutPath = “/security/logout”;
});

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor> ();
services.AddDistributedMemoryCache ();

services.AddHttpClient ();

services.AddMvc ()
.SetCompatibilityVersion (CompatibilityVersion.Version_2_2)
.AddJsonOptions (options =>
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

services.AddSession (options => {
options.Cookie.Name = “App.Marsala.Session”;
options.IdleTimeout = TimeSpan.FromHours (3);
options.Cookie.IsEssential = true;
});
}

public void Configure (IApplicationBuilder app, IHostingEnvironment env) {
if (env.IsDevelopment ()) {
app.UseDeveloperExceptionPage ();
}

app.UseSession ();
app.UseCookiePolicy ();
app.UseAuthentication ();
app.UseStaticFiles ();
app.UseMvc (
routes => {
routes.MapRoute (
name: “default”,
template: “{controller=Home}/{action=Index}/{id?}”
);
}
);
}
}