用户注销非常快 [英] Users log out very quickly
问题描述
我正在使用ASP.NET身份成员身份.这是Startup.Auth.cs代码:
I am using ASP.NET identity membership. This is the Startup.Auth.cs code:
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吗?
As you can see I've set expiretimespan
to 3 hours, but on the production server it doesn't work; it expires in about ten minutes. When I inspect elements MyLoginCookie still exists. On localhost it works fine. Why does it have problems on the production server? Do I need to set CookieDomain?
推荐答案
用户注销的原因是由于表单身份验证数据和视图状态数据的验证错误.可能由于多种原因而发生这种情况,包括在托管服务中使用Web服务器场.您应在项目webconfig
中选中<machineKey>
.请在此处中获取有关此信息的详细信息.如果您的webconfig
中没有<machineKey>
,请尝试在Webconfig中的<system.web>
之后添加以下代码:
The reason for users logging off is because of error in validation of forms-authentication data and view-state data. It could happen for different reasons including using web farm in hosting services.You should check <machineKey>
in your project webconfig
. Check here for details about that. If you don't have<machineKey>
in your webconfig
, try adding this piece of code after <system.web>
in your webconfig:
<machineKey
validationKey="AutoGenerate,IsolateApps"
decryptionKey="AutoGenerate,IsolateApps"
validation="HMACSHA256"
decryption="Auto"
/>
另一个选择是在webconfig中使用生成的ASP.NET机器密钥.我推荐的一些在线工具是此和
The other option is using generated ASP.NET Machine Key inside webconfig. There are some online tools which my recommended ones are this and this.
这篇关于用户注销非常快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!