I have an ASP.NET MVC 5 application that uses ASP.NET Identity 2.1.0 to authenticate users.
Everything worked fine in the past, but now I found out that persistent user sessions no longer work. I canβt say what change violated this, but it worked when I implemented Identity (converted the application from SimpleMembership ), and this is my logic that I have at the moment:
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: true);
SignInManager is my ApplicationSignInManager based on SignInManager<ApplicationUser, int> and model.RememberMe is true .
And my setup is:
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider { OnValidateIdentity = ApplicationCookieIdentityValidator.OnValidateIdentity( validateInterval: TimeSpan.FromMinutes(0), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) } }); app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
Everything works fine except save user sessions. I checked the cookies returned by my server and .AspNet.ApplicationCookie always returns as "valid for the current session" instead of any date in the future. So when I close and reopen the browser, I need to log in again ...
Does anyone have an idea why this is not working (anymore)?
PS: I redefined SignInAsync in my ApplicationSignInManager because there is some kind of user logic there, but I even checked with the debugger for the following call:
await base.SignInAsync(user, isPersistent, rememberBrowser);
isPersistent is true , so it should create a persisten cookie.
c # asp.net-mvc asp.net-mvc-5 asp.net-identity asp.net-identity-2
Chrfin
source share