Ivan Fioravanti - 405 - Sep 11, 2014

We’re facing an issue with HasRole method returning false using Redis as ICacheClient and we’re going crazy with this one.

Everything works properly with InMemoryCache. We are using a CustomUserSession, with MongoDB as IUserAuthRepository. 

Any clues?

Ivan Fioravanti:

Debugging we’ve seen that at line 38 of RequiredRoleAttribute.cs:

var session = req.GetSession();

session is retrieved from the ASPNET request, it’s not null, but it’s empty. while in Redis cache the session is full with all data.

Ivan Fioravanti:

I debugged this and I found something strange: problem lies in following line of GetSession in ServiceExtension.

var session = cache.Get<IAuthSession>(SessionFeature.GetSessionKey(sessionId));

using Redis as Cache is null, but if I call:

var session = cache.Get<AuthUserSession>(SessionFeature.GetSessionKey(sessionId));

session is correctly deserialized from Redis and everything works properly.

Ivan Fioravanti:

SOLVED!!!
I added: 
JsConfig<MyCustomAuthUserSession>.IncludeTypeInfo = true;

The strange thing is that I had:
ServiceStack.Text.JsConfig.ExcludeTypeInfo = false;

So it should have work in any case… strange. But it works!!!

Odd, it should be working by default. What other JsConfig settings do you have? Also does your MyCustomAuthUserSession DTO have [DataMember] properties, e.g:
https://github.com/ServiceStack/ServiceStack/wiki/Sessions#using-typed-sessions-in-servicestack

Ivan Fioravanti:

I had:
JsConfig.EmitCamelCaseNames = true;

And DataMember attribute was there.

Weird, I’ve got tests working in each Cache Provider for custom auth sessions: https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.Server.Tests/Properties/CacheClientTests.cs#L242
I’ll see if I can repro in a test project using a RedisClient Cache, otherwise will need a repro test case.

Still works in test integration project, I’ve added some test Session services using Redis CacheClient in this commit: https://github.com/ServiceStack/Test/commit/d55f132aeb7a0d069994e93a7b9891f7593b99c1

Everything seems to be working fine:
Url to get the session is:
http://test.servicestack.net/session
Url to login:
http://test.servicestack.net/login
Url to edit session:
http://test.servicestack.net/session/edit/ANYTEXT