Я не могу увеличить время ожидания сеанса в ASP.Net Core 2.0. Сессия истекает через каждые 20-30 минут. Когда я уменьшаю время до 1 минуты и отлаживаю его, оно работает нормально, но когда оно увеличивается до более чем 30 минут или часов / дней, оно не длится до указанной продолжительности.
Срок действия сеанса истек через 30 минут в режиме отладки, а также в IIS (размещено после публикации).
Пожалуйста, помогите.
options.IdleTimeout = TimeSpan.FromMinutes (180);
Я использую приведенный ниже код в файле startup.cs.
public void ConfigureServices (службы IServiceCollection)
{
services.AddMvc ();
// Adds a default in-memory implementation of IDistributedCache.
services.AddDistributedMemoryCache();
services.ConfigureApplicationCookie(options =>
{
options.Cookie.HttpOnly = true;
options.Cookie.Expiration = TimeSpan.FromDays(3);
options.ExpireTimeSpan= TimeSpan.FromDays(3);
options.SlidingExpiration = true;
});
services.AddSession(options =>
{
// Set a short timeout for easy testing.
options.IdleTimeout = TimeSpan.FromMinutes(180);
});
services.AddSingleton<IConfiguration>(Configuration);
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IConfigurationSettings configurationSettings)
{
//
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseSession();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseExceptionHandler(
builder =>
{
builder.Run(
async context =>
{
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.Response.ContentType = "application/json";
var ex = context.Features.Get<IExceptionHandlerFeature>();
if (ex != null)
{
if(ex.Error is SessionTimeOutException)
{
context.Response.StatusCode = 333;
}
if (ex.Error is UnauthorizedAccessException)
{
context.Response.StatusCode =999;
}
var err = JsonConvert.SerializeObject(new Error()
{
Stacktrace = ex.Error.StackTrace,
Message = ex.Error.Message
});
await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes(err), 0, err.Length).ConfigureAwait(false);
}
});
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
});
app.UseSpa(spa =>
{
// To learn more about options for serving an Angular SPA from ASP.NET Core,
// see https://go.microsoft.com/fwlink/?linkid=864501
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
}