Reputation: 397
I am having trouble while setting session information on Redis. Below are the configurations I have made.
appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[]
{
new BasicAuthProvider
{
SessionExpiry = new TimeSpan(1000, 0, 0)
},
new CredentialsAuthProvider(appSettings)
{
SessionExpiry = new TimeSpan(1000, 0, 0)
}
}));
container.Register<IRedisClientsManager>(c =>
new PooledRedisClientManager("RedisServer:6379"));
container.Register(c => c.Resolve<IRedisClientsManager>().GetCacheClient());
Below is the code where I am trying to get and set some session information but after setting, I am getting older values. Not sure what I am doing wrong. Please suggest.
//get
var user=SessionAs<CustomUserSession>();
//set
var userSetting=SessionAs<CustomUserSession>();
userSetting.OrganisationId=01;
If I try to get user information now, it will be an older value, not the latest one.
Upvotes: 0
Views: 61
Reputation: 143339
If you modify the Session it needs to saved back to the ICacheClient
with IRequest.SaveSession()
, e.g:
var userSession = base.SessionAs<CustomUserSession>();
userSession.OrganisationId = 1;
base.Request.SaveSession(userSession); //Persists userSession to ICacheClient
Upvotes: 2