用户很快就会退出

我正在使用ASP.NET身份会员资格。 这是Startup.Auth.cs代码:

app.CreatePerOwinContext(EFDbContext.Create); app.CreatePerOwinContext(ApplicationUserManager.Create); app.CreatePerOwinContext(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( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) } }); 

正如您所看到的,我将expiretimespan设置为3小时,但在生产服务器上它不起作用; 它会在大约十分钟后到期。 当我检查元素MyLoginCookie仍然存在时。 在localhost上工作正常。 为什么在生产服务器上有问题? 我需要设置CookieDomain吗?

用户注销的原因是表单身份validation数据和视图状态数据的validation错误。 它可能由于各种原因而发生,包括在托管服务中使用Web场。您应该检查项目webconfig 。 点击此处查看详细信息。 如果您的webconfig没有 ,请尝试在webconfig 之后添加这段代码:

   

另一个选项是在webconfig中使用生成的ASP.NET Machine Key。 有一些在线工具,我推荐的是这个和这个 。