用户很快注销用户很快注销(Users log out very quickly)

2019-05-12 06:36发布

我使用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小时,但在生产服务器上它不工作; 过期在大约10分钟。 当我检查元素MyLoginCookie仍然存在。 在本地主机上正常工作。 为什么它在生产服务器上的问题? 我是否需要设置CookieDomain?

Answer 1:

其原因为用户注销是因为在表单的认证数据和视图状态数据的验证错误的。 这可能发生的原因不尽相同,包括在托管services.You应检查使用Web场<machineKey>在您的项目webconfig 。 检查此有关的详细信息。 如果你没有<machineKey>webconfig ,尝试添加这段代码后<system.web>在webconfig:

    <machineKey 
    validationKey="AutoGenerate,IsolateApps"
    decryptionKey="AutoGenerate,IsolateApps"
    validation="HMACSHA256"
    decryption="Auto"
    />

使用所产生的其他选项里面webconfig ASP.NET计算机密钥。 有一些在线工具,我推荐的有这个和这个 。



文章来源: Users log out very quickly