I've recently started changing one of my projects over to asp .net identity 2 from my home grown authentication. I've got an issue with it though which is affecting the users. For one reason or another in development or production it seems to be logging people out with no real pattern or explanation.
I'm using just regular CookieAuthentication
with custom identity tables in the database with a custom UserManager and RoleManager so I can use Int32 for the PK instead of string, pretty straight forward.
This is the configuration I'm using in my startup file.
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
SlidingExpiration = true,
ExpireTimeSpan = TimeSpan.FromHours(1),
Provider = new CookieAuthenticationProvider
{
OnApplyRedirect = ctx =>
{
if (!ctx.Request.Path.StartsWithSegments(new PathString("/api")) && !ctx.Request.Path.StartsWithSegments(new PathString("/service")))
{
ctx.Response.Redirect(ctx.RedirectUri);
}
},
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<CustomUserManager, WebAccount, int>
(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
getUserIdCallback: (id) => (Int32.Parse(id.GetUserId()))
)
}
});
I've seen it where people are editing some data via a form and in the time from loading the form to clicking save they have been logged out and redirected to the login page, losing there changes.
I cant quite figure out why it would be doing this so if anyone could shed some light it would be much appreciated!
Thanks in advance!