Session MVC4 and ServiceStack in Redis

I have a new MVC4 project on which I installed the ServiceStack MVC starter pack (version 4.0.12 from MyGET) to load service stack sessions.

In my, AppHostmy user session is configured as:

Plugins.Add(new AuthFeature(() => new CustomUserSession(),
    new IAuthProvider[] {
        new CredentialsAuthProvider(config)
    }));

A user session is as follows:

public class CustomUserSession : AuthUserSession
{
    public string Hello { get; set; }
}   

And ICacheClientregistered as a redis client:

// register the message queue stuff 
var redisClients = config.Get("redis-servers", "redis.local:6379").Split(',');
var redisFactory = new PooledRedisClientManager(redisClients);
var mqHost = new RedisMqServer(redisFactory, retryCount: 2);
container.Register<IRedisClientsManager>(redisFactory); // req. to l
container.Register<IMessageFactory>(mqHost.MessageFactory);

container.Register<ICacheClient>(c =>
                        (ICacheClient)c.Resolve<IRedisClientsManager>()
                        .GetCacheClient())
                        .ReusedWithin(Funq.ReuseScope.None);      

Then I created a ControllerBase, which for simplicity loads and saves a user session for each request:

public abstract class ControllerBase :  ServiceStackController<CustomUserSession>
{
    protected override IAsyncResult BeginExecute (System.Web.Routing.RequestContext requestContext, AsyncCallback callback, object state)
    {
        ViewBag.Session = this.UserSession;
        return base.BeginExecute (requestContext, callback, state);
    }

    protected override void EndExecute(IAsyncResult asyncResult)
    {
        SaveSession(null);

        base.EndExecute(asyncResult);
    }
    public void SaveSession(TimeSpan? expiresIn = null)
    {
        Cache.CacheSet(SessionFeature.GetSessionId(), UserSession, expiresIn ?? new TimeSpan(0, 30, 0));
    }
}

Hello, "" , SaveSession, . . , Redis, blob:

{
   "createdAt": "/Date(-62135596800000-0000)/",
   "lastModified": "/Date(-62135596800000-0000)/",
   "providerOAuthAccess": [],
   "isAuthenticated": true,
   "tag": 0
}

. - , /?

=== UPDATE ===

- AuthUserSession, - , SS - .

+4
1

AuthUserSession DataContract, v4, [DataMember], :

public class CustomUserSession : AuthUserSession
{
    [DataMember]
    public string Hello { get; set; }
}   
+3

All Articles