Skip to content
Browse files

Refactored CookieAuthenticationModule#RenewCookieIfExpiring

  • Loading branch information...
1 parent 2883a49 commit 5a490cce81ea2b9219b94fc2aed4d180595515ca @mehrdada mehrdada committed Aug 13, 2012
Showing with 14 additions and 13 deletions.
  1. +14 −13 AppHarbor.Web.Security/CookieAuthenticationModule.cs
View
27 AppHarbor.Web.Security/CookieAuthenticationModule.cs
@@ -58,21 +58,22 @@ private void OnAuthenticateRequest(object sender, EventArgs e)
private void RenewCookieIfExpiring(HttpContext context, CookieProtector protector, AuthenticationCookie authenticationCookie)
{
- if (_configuration.SlidingExpiration && authenticationCookie.IsExpired(TimeSpan.FromTicks(_configuration.Timeout.Ticks / 2)))
+ if (!_configuration.SlidingExpiration || !authenticationCookie.IsExpired(TimeSpan.FromTicks(_configuration.Timeout.Ticks / 2)))
{
- authenticationCookie.Renew();
- context.Response.Cookies.Remove(_configuration.CookieName);
- var newCookie = new HttpCookie(_configuration.CookieName, protector.Protect(authenticationCookie.Serialize()))
- {
- HttpOnly = true,
- Secure = _configuration.RequireSSL,
- };
- if (!authenticationCookie.Persistent)
- {
- newCookie.Expires = authenticationCookie.IssueDate + _configuration.Timeout;
- }
- context.Response.Cookies.Add(newCookie);
+ return;
+ }
+ authenticationCookie.Renew();
+ context.Response.Cookies.Remove(_configuration.CookieName);
+ var newCookie = new HttpCookie(_configuration.CookieName, protector.Protect(authenticationCookie.Serialize()))
+ {
+ HttpOnly = true,
+ Secure = _configuration.RequireSSL,
+ };
+ if (!authenticationCookie.Persistent)
+ {
+ newCookie.Expires = authenticationCookie.IssueDate + _configuration.Timeout;
}
+ context.Response.Cookies.Add(newCookie);
}
private bool IsLoginPage(HttpRequest request)

0 comments on commit 5a490cc

Please sign in to comment.
Something went wrong with that request. Please try again.