Skip to content

Commit 0c57a51

Browse files
authored
use non-session cookies in bundle with an expiration date
Many browsers do not clean up session cookies when you close them. So the rule of thumb must be: for having a consistent behaviour across all browsers, don't rely solely on browser behaviour for proper clean-up of session cookies. It is safer to use non-session cookies (IsPersistent == true) in bundle with an expiration date. See http://blog.petersondave.com/cookies/Session-Cookies-in-Chrome-Firefox-and-Sitecore/
1 parent 50779df commit 0c57a51

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/AbpCompanyName.AbpProjectName.WebSpaAngular/Controllers/AccountController.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,21 @@ private async Task SignInAsync(User user, ClaimsIdentity identity = null, bool r
144144
}
145145

146146
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
147-
AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = rememberMe }, identity);
147+
// Many browsers do not clean up session cookies when you close them. So the rule of thumb must be:
148+
// For having a consistent behaviour across all browsers, don't rely solely on browser behaviour for proper clean-up
149+
// of session cookies. It is safer to use non-session cookies (IsPersistent == true) in bundle with an expiration date.
150+
// See http://blog.petersondave.com/cookies/Session-Cookies-in-Chrome-Firefox-and-Sitecore/
151+
if (rememberMe) {
152+
_authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = true }, identity);
153+
} else {
154+
_authenticationManager.SignIn(
155+
new AuthenticationProperties
156+
{
157+
IsPersistent = true,
158+
ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(int.Parse(System.Configuration.ConfigurationManager.AppSettings["AuthSession.ExpireTimeInMinutes.WhenNotPersistet"] ?? "30"))
159+
},
160+
identity);
161+
}
148162
}
149163

150164
private Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName)
@@ -549,4 +563,4 @@ public PartialViewResult _AccountLanguages()
549563

550564
#endregion
551565
}
552-
}
566+
}

0 commit comments

Comments
 (0)