Strange usersession behaviour

I suspect this will be difficult to replicate, but we are seeing the following. We have overridden AppHost.GetCacheClient to use the .WithPrefix to namespace tenant settings.

 public override ICacheClient GetCacheClient(IRequest req)
            {
                var tenant = CreateTenant();
                return base.GetCacheClient(req).WithPrefix(tenant.Id+ ":");
            }

We also use a response filter attribute to slide session expiration on certain api calls.

public override void Execute(IRequest req, IResponse res, object responseDto)
        {
            var session = req.GetSession();
            var tenant = req.TryResolve<MultiTenantManager>().Tenant;
            if (session != null && session.IsAuthenticated)
                req.SaveSession(session, tenant.LoginExpiry);
        }

This has worked for years.

5.9 - works
5.13 - the ResponseFilterAttribute creates a session with the prefix, but logging in creates iauthusersession:urn entry without the Prefix.

This is still the case in 6.0.2. Any ideas?

It’s likely due to ServiceStack using Async APIs internally, i.e. you’ll also need to override GetCacheClientAsync() as well.

To help track down how Sessions are being saved you can override the OnSaveSession* APIs in your AppHost and debug the callstack to find out what’s calling it:

public override void OnSaveSession(IRequest httpReq, IAuthSession session, TimeSpan? expiresIn = null)
{
    base.OnSaveSession(httpReq, session, expiresIn);
}

public override Task OnSaveSessionAsync(IRequest httpReq, IAuthSession session, TimeSpan? expiresIn = null, CancellationToken token = default)
{
    return base.OnSaveSessionAsync(httpReq, session, expiresIn, token);
}

If you call the sync IRequest.SaveSession() APIs it will call the sync OnSaveSession() method, ServiceStack internally will use async APIs wherever possible.