Skip to content

Commit 50779df

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 c5be3f3 commit 50779df

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

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

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

145159
private Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName)
@@ -547,4 +561,4 @@ public PartialViewResult _AccountLanguages()
547561

548562
#endregion
549563
}
550-
}
564+
}

0 commit comments

Comments
 (0)