【发布时间】:2021-01-17 01:50:03
【问题描述】:
我正在使用 ASP.NET 身份成员资格。这是 Startup.Auth.cs 代码:
app.CreatePerOwinContext(EFDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
ExpireTimeSpan = TimeSpan.FromHours(3),
CookieName = "MyLoginCookie",
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
如您所见,我已将 expiretimespan 设置为 3 小时,但在生产服务器上它不起作用;大约十分钟后到期。当我检查元素时 MyLoginCookie 仍然存在。在本地主机上它工作正常。为什么在生产服务器上有问题?我需要设置 CookieDomain 吗?
【问题讨论】:
-
It expires about in ten minutes- 在什么情况下会发生这种情况?是 10 分钟不活动还是客户端正在积极执行请求并且在初始登录后 10 分钟仍然过期?浏览器中 cookie 的到期日期/时间是什么时候(应该可以通过您的浏览器开发工具查看)?您尝试过哪些浏览器?on production server it doesn't work- 它在哪里按预期工作(仅在本地或在测试服务器上)?您还可以提供什么来提供更多见解? -
(制作)如果用户在十分钟内没有发送http请求,他就会退出。在本地我大约 30 分钟处于非活动状态,但是当我回来时,我直到登录。我正在使用 google chrome,并且在本地和生产服务器上检查元素 MyLoginCookie 过期时间为 N/A
-
你看过this write up了吗?它很好地解释了超时的差异和预期行为。
-
是的,我读过。也许这是一个iis问题,但不知道。它在本地运行良好:(
-
没有任何想法? ://
标签: c# asp.net-mvc identity