Asp.Net Identity不记得记录用户

时间:2018-01-19 19:10:46

标签: asp.net asp.net-mvc asp.net-identity

我有一个带有Asp.Net Identity的ASP.MVC应用程序。我想保持登录用户的会话一年。我将cookie设置为一年,但应用程序在几天后询问用户名和密码。我不希望应用程序再次询问登录信息。

我该怎么办?

app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                ExpireTimeSpan = TimeSpan.FromDays(365),
                LoginPath = new PathString("/login"),
                SlidingExpiration = true,
                Provider = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, int>
                        (TimeSpan.FromDays(365),
                            (manager, user) =>
                                user.GenerateUserIdentityAsync(manager), id => (Int32.Parse(id.GetUserId()))
                        ),
                    OnResponseSignIn = ctx =>
                    {
                        ctx.Properties.AllowRefresh = true;
                        ctx.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddYears(1);
                    }
                }
            });

0 个答案:

没有答案