A few days ago, I decided to upgrade my web application from asp.net core 1.1 to core 2.0. Everything seems to work fine after minor changes, except that authentication does not persist for more than 20-30 minutes.
We can take the default example from Visual Studio, because I have the same problem in my own web application and in the "ASP.NET Main Web Application" -> .NET Framework 4.6.1 + ASP.NET Core 2.0 + MVC + Separate user accounts .
The default configuration and must be registered by users within 14 days:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
...
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseAuthentication();
...
}
, 20-30 . ( " " ) , . , , cookie cookie . 20-30 , , cookie ( , ). , .
cookie , :
services.ConfigureApplicationCookie(options => {
options.ExpireTimeSpan = TimeSpan.FromDays(1);
});
20-30 , - :
services.AddSession(options =>
{
options.Cookie.Expiration = TimeSpan.FromDays(1);
options.IdleTimeout = TimeSpan.FromDays(1);
});
ASP.NET Core 1.1.