I talked about sliding sessions before. With the release of WIF 4.5, a lot of changes were introduced.
So to get sliding sessions working in .NET 4.5, replace the old implementation of the SessionSecurityTokenReceived method with the following:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SessionSecurityTokenReceived(object sender, | |
System.IdentityModel.Services.SessionSecurityTokenReceivedEventArgs e) | |
{ | |
DateTime now = DateTime.UtcNow; | |
SessionSecurityToken sst = e.SessionToken; | |
DateTime validFrom = sst.ValidFrom; | |
DateTime validTo = sst.ValidTo; | |
if ((now < validTo) && (now > validFrom.AddMinutes( (validTo.Minute - validFrom.Minute) / 2)) ) | |
{ | |
SessionAuthenticationModule sam = sender as SessionAuthenticationModule; | |
e.SessionToken = sam.CreateSessionSecurityToken(sst.ClaimsPrincipal, | |
sst.Context, | |
now, | |
now.AddMinutes(2), | |
sst.IsPersistent); | |
e.ReissueCookie = true; | |
} | |
} |