C#Asp.net MVC的身份,用户注销很快 [英] C# Asp.net mvc identity, users logging out very quickly

查看:194
本文介绍了C#Asp.net MVC的身份,用户注销很快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Asp.net身份的成员资格。这是Startup.Auth.cs code:

I am using Asp.net identity membership. This is 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依然存在的元素。在本地主机上它的工作原理fine.Why它的生产服务器上的问题?我是否需要设置CookieDomain?请帮我,近六小时,我想找到解决办法,但没有运气。

As you can see i've set expiretimespan to 3 hours, but on production server it doesn't work. It expires about in ten minutes But when i check inspect elements MyLoginCookie still exists. On localhost it works fine.Why it has problems on production server? Do i need to set CookieDomain? Please help me, almost six hours i'm trying to find solution but with no luck.

推荐答案

原因用户注销是因为在表单的身份验证数据和视图状态数据的验证错误。它可能发生不同的原因,其中包括举办services.You应检查&LT使用Web场;将machineKey&GT; 项目中的 webconfig 。检查这里,了解有关细节。如果你没有&LT;的machineKey&GT; webconfig ,尝试添加这块code后&LT;&的System.Web GT; 在webconfig:

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计算机密钥。还有我推荐的是并的这个

这篇关于C#Asp.net MVC的身份,用户注销很快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆