Я использую dot net core 2.0 с MVC.Мне нужно для достижения этой функциональности.Если пользователь бездействует в течение 15 минут, мне нужно обновить и перенаправить на страницу входа.Я использовал проверку подлинности претензий.Вот что я попробовал в starup.cs
services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.Cookie.HttpOnly = true;
//options.Cookie.Expiration = TimeSpan.FromDays(150);
options.ExpireTimeSpan = TimeSpan.FromSeconds(15);
options.LoginPath = "/Account/Login"; // If the LoginPath is not set here, ASP.NET Core will default to /Account/Login
options.LogoutPath = "/Account/Logout"; // If the LogoutPath is not set here, ASP.NET Core will default to /Account/Logout
options.AccessDeniedPath = "/Account/AccessDenied"; // If the AccessDeniedPath is not set here, ASP.NET Core will default to /Account/AccessDenied
options.SlidingExpiration = true;
});
"options.ExpireTimeSpan = TimeSpan.FromSeconds (15);"это то, что я думал, что поможет мне выйти из системы через 15 секунд (для целей тестирования фактически 15 минут).
Вот весь мой запуск
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = 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.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, ApplicationRole>(config =>
{
config.SignIn.RequireConfirmedEmail = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddScoped<UserManager<ApplicationUser>>();
services.Configure<IdentityOptions>(options =>
{
// Password settings
options.Password.RequireDigit = true;
options.Password.RequiredLength = 8;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = false;
options.Password.RequiredUniqueChars = 6;
// Lockout settings
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
options.Lockout.MaxFailedAccessAttempts = 10;
options.Lockout.AllowedForNewUsers = true;
// User settings
options.User.RequireUniqueEmail = true;
});
services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.Cookie.HttpOnly = true;
//options.Cookie.Expiration = TimeSpan.FromDays(150);
options.ExpireTimeSpan = TimeSpan.FromSeconds(15);
options.LoginPath = "/Account/Login"; // If the LoginPath is not set here, ASP.NET Core will default to /Account/Login
options.LogoutPath = "/Account/Logout"; // If the LogoutPath is not set here, ASP.NET Core will default to /Account/Logout
options.AccessDeniedPath = "/Account/AccessDenied"; // If the AccessDeniedPath is not set here, ASP.NET Core will default to /Account/AccessDenied
options.SlidingExpiration = true;
});
services.Configure<EmailSettings>(Configuration.GetSection("EmailSettings"));
// Add application services.
services.AddTransient<IEmailSender, EmailSender>();
//Common Services
services.AddTransient<CommonService, CommonService>();
services.AddMvc()
.AddJsonOptions(options =>
options.SerializerSettings.ContractResolver = new DefaultContractResolver());
services.Configure<AppSettings>(Configuration.GetSection("ApplicationSettings"));
// Add Kendo UI services to the services container
services.AddKendo();
//Date Format
services.Configure<DateSettings>(Configuration.GetSection("DateSettings"));
//Templates
services.Configure<Templates>(Configuration.GetSection("Templates"));
//Themes
services.Configure<ThemeSettings>(Configuration.GetSection("ThemeSettings"));
//Title
services.Configure<TitleSettings>(Configuration.GetSection("TitleSettings"));
//Google reCaptcha
services.Configure<GoogleReCaptcha>(Configuration.GetSection("GoogleReCaptcha"));
services.Configure<LoginAttemptsToCaptcha>(Configuration.GetSection("LoginAttemptsToCaptcha"));
services.Configure<PhysicalExamination>(Configuration.GetSection("PhysicalExamination"));
//Reset Password Settings
//var reset = services.Configure<ResetPasswordSettings>(Configuration.GetSection("ResetPasswordSettings"));
var resetsettingsSection = Configuration.GetSection("ApplicationSettings");
var settings = resetsettingsSection.Get<AppSettings>();
services.Configure<DataProtectionTokenProviderOptions>(options =>
{
options.TokenLifespan = TimeSpan.FromMinutes(settings.ResetPasswordExpiryTime);
});
//services.AddMvc().AddSessionStateTempDataProvider();
//services.AddSession();
//services.AddSession(options =>
//{
// options.IdleTimeout = TimeSpan.FromSeconds(10);
//});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
UserManager<ApplicationUser> userManager,
RoleManager<ApplicationRole> roleManager, ApplicationDbContext context)
{
//app.UseMiddleware<AuthenticationMiddleware>();
//app.UseMiddleware<ErrorHandlingMiddleware>();
app.UseAuthenticationMiddleware();
if (env.IsDevelopment())
{
//app.UseBrowserLink();
//app.UseDeveloperExceptionPage();
//app.UseDatabaseErrorPage();
//app.UseExceptionHandler("/Home/Error");
}
else
{
//app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseAuthentication();
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
if (!serviceScope.ServiceProvider.GetService<ApplicationDbContext>().AllMigrationsApplied())
{
serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate();
}
AppIdentityDataInitializer.SeedAdminUser(userManager, roleManager, context);
serviceScope.ServiceProvider.GetService<ApplicationDbContext>().EnsureSeeded();
}
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
// Configure Kendo UI
//app.UseKendo(env);
//app.UseSession();
}
}
Может ли кто-нибудь помочь мне добиться этого.