Recently I created my new website in .net core 2.0 and I'm using a persistent cookie in authentication. I'm also using persistent culture cookie for language.
my website hosted in azure shared pool and I didn't specify any machine key.
Problem. When I re-open my website after few hours of inactivity (new browser) I lost my auth cookie and I need to log in again but culture cookie works as per the last session.
I also setup Application Insights availability to keep warm up my application (ping website in every 10 min from 2 different location).
LoginController
if (this.accountService.ValidateOTP(phoneNumber, otp))
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.MobilePhone, phoneNumber),
new Claim(ClaimTypes.Name, phoneNumber)
};
var userIdentity = new ClaimsIdentity("Custom");
userIdentity.AddClaims(claims);
ClaimsPrincipal userPrincipal = new ClaimsPrincipal(userIdentity);
//await HttpContext.SignOutAsync("AnimalHubInstance");
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
userPrincipal,
new AuthenticationProperties
{
IsPersistent = true,
ExpiresUtc = DateTime.Now.AddYears(1),
});
}
Startup
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(option =>
{
option.LoginPath = new PathString("/Account/Unauthorized");
option.LogoutPath = new PathString("/Account/Logout");
option.Cookie.Name = ".myAuth";
option.ExpireTimeSpan = TimeSpan.FromDays(365);
option.Cookie.Expiration = TimeSpan.FromDays(365);
});