Switching to WIF SessionMode in ASP.NET
- by Your DisplayName here!
To make it short: to switch to SessionMode (cache to server) in ASP.NET, you need
to handle an event and set a property. Sounds easy – but you need to set it in the
right place.
The most popular blog post about this topic is from Vittorio.
He advises to set IsSessionMode in WSFederationAuthenticationModule_SessionSecurityTokenCreated.
Now there were some open questions on forum, like this one.
So I decided to try it myself – and indeed it didn’t work for me as well. So I digged
a little deeper, and after some trial and error I found the right place (in global.asax):
void WSFederationAuthenticationModule_SecurityTokenValidated(
object sender, SecurityTokenValidatedEventArgs e)
{
FederatedAuthentication.SessionAuthenticationModule.IsSessionMode
= true;
}
Not sure if anything has changed since Vittorio’s post – but this worked for me.
While playing around, I also wrote a little diagnostics tool that allows you to look
into the session cookie (for educational purposes). Will post that soon.
HTH