Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Users log out very quickly

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))

            }
        });

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?

like image 583
user3857731 Avatar asked Mar 28 '16 12:03

user3857731


People also ask

How do I turn off auto logoff?

Go to Advanced power settings (click on Windows button, write power options, click on Power Options, in the selected plan click on the Change plan settings, click on the Change advanced power settings). 9. Click Sleep, then System unattended sleep timeout, then change these settings from 2 Minutes to 20 for example.

How do I stop my computer from automatically signing me out?

Press Windows icon key on the keyboard, type Settings and select the top most search result. Select Personalization and click on Lock screen from the left side panel of the window. Click on Screen timeout settings and set the time limit or select Never from the drop down bar under Screen option.

How do you log out fast?

Log off using “Ctrl” + “Alt” + “Delete” You can also find the sign out option in the menu accessed by pressing "Ctrl" + "Alt" + "Delete" on your keyboard. 2.

Why does my computer keep logging me out of everything?

You might get signed out of everything if your cache data gets corrupted. Clearing cache data to remove the junk and broken cookies to fix the sign-out problem.


1 Answers

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"
    />

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.

like image 81
Hadee Avatar answered Oct 03 '22 07:10

Hadee