英文:
How to increase session timeout in .net core 5
问题
以下是您要翻译的内容:
"我已经尝试延长我的 .net core 5.0 应用程序中的会话超时时间,但似乎应用程序具有默认或覆盖方法,将会话超时时间设置为小于30分钟。
以下是我尝试配置会话超时的地方。
services.ConfigureApplicationCookie(options =>
{
// Cookie 设置
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromHours(48);
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
options.AccessDeniedPath = new PathString("/Administration/AccessDenied");
options.SlidingExpiration = true;
});
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromHours(48);
options.Cookie.IsEssential = true;
});
我做错了什么?请帮助。"
英文:
I have tried to extend the session timeout in my .net core 5.0 application but it seems the application has a default or an overriding method that enables session timeout to less than 30 minutes.
The below are where I have tried configuring the session timeout.
services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromHours(48);
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
options.AccessDeniedPath = new PathString("/Administration/AccessDenied");
options.SlidingExpiration = true;
});
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromHours(48);
options.Cookie.IsEssential = true;
});
What is it am I doing wrong.
Kindly assist.
答案1
得分: 1
我测试了你的显示代码,应该是有效的,以下是测试结果: 你可以从图片中看到,会话的过期时间是有效的。
所以也许你可以尝试以下步骤来检查是什么导致了你的问题:
- 确保你在 Startup.cs 中添加了 app.UseSession();
- 检查你的代码中是否有其他地方设置了较短的会话超时时间。例如,如果你有一个中间件设置了更短的会话超时时间,它可能会覆盖你的配置。
- 检查会话中间件是否是在身份验证中间件之后添加的。身份验证中间件设置了自己的超时时间,如果会话中间件在其之前添加,它将使用那个值。
或者你可以分享更多关于你的项目的信息,我们可以检查可能导致问题的原因。
英文:
I test your showing codes which should be working, here is the test result: You can see from the picture, the expire time of session is working
So maybe you can try these steps to check what cause your issue:
- Make sure you are adding the app.UseSession(); in the Startup.cs
- Check that there are no other places in your code where the session timeout is being set as a shorter time. For example, if you have a middleware that sets the lower session timeout, it could be overriding your configuration.
- Check that the session middleware is being added after the authentication middleware. The authentication middleware sets its own timeout, and if the session middleware is added before it, it will use that value instead.
Or maybe you can share more information of your project and we can check what may cause your issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论