【发布时间】:2018-11-23 17:28:57
【问题描述】:
我正在使用带有 Microsoft Identity 的 ASP.NET Core 2.1,并且用户抱怨他们在闲置大约 30 分钟后不断被重定向到登录屏幕。我在 ExpireTimeSpan 中设置了 60 分钟,但它从来没有持续这么长时间。有什么建议吗?
这就是我在 Startup.cs 文件中的内容:
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IRFDbRepository, RFDbRepository>();
var connection = _configuration.GetConnectionString("RFDbConnection");
services.Configure<ConnectionStrings>(_configuration.GetSection("ConnectionStrings"));
services.AddDbContext<IdentityDbContext>(options => options.UseSqlServer(connection));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddRazorPagesOptions(options =>
{
options.AllowAreas = true;
options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
});
services.AddIdentity<User, UserRole>().AddDefaultTokenProviders();
services.AddTransient<IUserStore<User>, UserStore>();
services.AddTransient<IRoleStore<UserRole>, RoleStore>();
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Identity/Account/Login";
options.LogoutPath = "/Identity/Account/Logout";
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
options.SlidingExpiration = true;
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IRFDbRepository rFDbRepository)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
loggerFactory.AddFile(_configuration.GetValue<string>("Logging:LogFile"));
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "ActionApi",
template: "api/{controller}/{action}/{id?}");
});
}
【问题讨论】:
-
尝试在
var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: true);中将RememberMe设置为True -
现在试过了,恐怕没有什么不同。还是谢谢
标签: c# asp.net-core asp.net-identity