D
D
Dmitry Filandor2017-02-09 15:30:37
ASP.NET
Dmitry Filandor, 2017-02-09 15:30:37

How to make AspNet.Identity remember input?

Hello. Site asp mvc 5, authorization standard (individual) - Microsoft.AspNet.Identity
I log in (daw remember me - I click) and it lasts for a day ... then I need to log in again.
Googled this question, here's what I added to Startup.Auth.cs

public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.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("/Home/Maintance"),
               LoginPath = new PathString("/Account/Login"),


                    

                Provider = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
             validateInterval: TimeSpan.FromDays(40),
            regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
                },
                SlidingExpiration = false,
                ExpireTimeSpan = TimeSpan.FromDays(40)
            });


            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

#decision
If you have hosting, then perhaps there is a farm there, and the matter is in the Machine Key.
We need to generate a new unique machine key and write it to web.config:
here we generate www.allkeysgenerator.com/Random/ASP-Net-MachineKey... and paste it into the webconfig

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2017-02-09
@LifeAct

SlidingExpiration = true,
and
can be left with the default settings.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question