It seems if i change the sessiontoken to the following code snip it works. Not sure if thats the right thing or not.
var sessionToken = new SessionSecurityToken(principal)
{
IsPersistent = true,
};
Question
How do you setup shared caching with a dedicated cache worker role and multiple instances of a webrole? dotnet 4.5.1 mvc 5.1.
I have a sessiontoken i'm trying to use for authentication/authorization. The token has a long validto/from times.
var sessionToken = new SessionSecurityToken(principal)
{
IsReferenceMode = true,
};
FederatedAuthentication.WSFederationAuthenticationModule.
SetPrincipalAndWriteSessionToken(sessionToken, true);
I added a cache worker role and configured it by enabling cache and setting it to dedicated. It created a default named cache setting with 30min sliding window LRU policy.
In my web.config of my webroles
<sessionState mode="Custom" customProvider="SessionProvider">
<providers>
<add name="SessionProvider"
type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"
cacheName="default"
dataCacheClientName="default"
applicationName="MyApp"/>
</providers>
</sessionState>
<dataCacheClients>
<dataCacheClient name="default">
<autoDiscover isEnabled="true" identifier="CacheWorkerRole" />
</dataCacheClient>
</dataCacheClients>
It seems to work with one instance, but fails when I introduce more. It seems to work for a minute or two then it vanishes. Like one instance is not aware of the cache. Even if I click around a bit to try to get to the first instance it appears to be gone.
It seems that I can add/read things from the cache manually from each instance.
I must have WIF or Caching misconfigured.
Ideas?
Thanks
Solution
It seems if i change the sessiontoken to the following code snip it works. Not sure if thats the right thing or not.
var sessionToken = new SessionSecurityToken(principal)
{
IsPersistent = true,
};