Authentication Required popup after restarting ServiceStack server

I am using the cookie based authentication in my javascript client. This is working fine. I use the Credentials Auth, getting the cookie and all all other calls work fine.
But… when I restart my server, the following call in the client code in the browser is getting this Authentication Required popup where you have to enter credentials. How can I avoid this?
Even when I enter credentials in the popup they don’t work.
I tried to intercept this client side, but the popup keeps appearing.

Is there a setting in the server I have to set in order to keep the cookie OK between server restarts? I already give the RememberMe property in the Auth call.
Thanks.

The Session Cookies point to an Authenticated UserSession in the registered ICacheClient, in order to preserve Authenticated Sessions after App restarts it must be configured to use a distributed caching provider (I.e any caching provider except Memory Cache Client). Alternatively you could use a stateless Auth Provider like JWT.

Ok thanks. I am now using the OrmLiteCacheClient and that works fine.
However, I saw that the ExpiryDate is now set to 1 month. Is there a way to have NO expiry on the session.
My idea is that the cookie itself has a long expiry, so I would like to set the expiry of the sessions also to 99 years for example. I saw some docs on extending the session, but when I user does not log on for a month this would not help.

Yep, since its persistent and preserved after App Domain restarts.

Ok thanks. I am now using the OrmLiteCacheClient and that works fine.
However, I saw that the ExpiryDate is now set to 1 month. Is there a way to have NO expiry on the session.
My idea is that the cookie itself has a long expiry, so I would like to set the expiry of the sessions also to 99 years for example. I saw some docs on extending the session, but when I user does not log on for a month this would not help.

Override OnSaveSession() in your AppHost, use the same implementation but don’t pass an expiry date to CacheSet.

I added following code:

GlobalResponseFilters.Add((req, res, dto) =>
{
     var session = req.GetSession();
     if (session != null)
          req.SaveSession(session, TimeSpan.FromDays(365*10));
});

is this also OK?

No, that doesn’t override when the Session is saved internally, overriding OnSaveSession() does. If you’re happy for a 10 year Session Expiry you can just override GetDefaultSessionExpiry() instead.

Great. That was what I was looking for!

1 Like