Fiz um programa em ASP.NET Core
MVC, que tem a classe Startup
como:
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.AddIdentity<AppUser, IdentityRole>()
.AddEntityFrameworkStores<idDataContext>()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(opts =>
{
opts.LoginPath = "/Account/Login";
opts.AccessDeniedPath = "/Account/AccessDenied";
opts.ExpireTimeSpan = TimeSpan.FromHours(4);
});
//...
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddMemoryCache();
services.AddSession();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, AppFeatures features)
{
//...
app.UseAuthentication();
//...
app.UseCookiePolicy();
app.Use(async (context, next) =>
{
if (context.Request.Path.Value.Contains("error"))
throw new Exception("Erro: caminho contém 'error'!");
await next();
});
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseFileServer();
}
}
Estou a indicar que a cookie do login e a cookie da sessão (com dados da minha app) duram 4h? Falta indicar isto em mais algum lado?
É que aparentemente as sessões não duram 4h no cliente. Existe algum erro?
Obrigado.