Search code examples
c#.netservicestackhttpserver

ServiceStack ungraceful client disconnect


In a ServiceStack app is there any way to determine that the client has ungracefully disconnected? I would like to get a list of users that are online, but

var sessionPattern = IdUtils.CreateUrn<IAuthSession>("");
var sessionKeys = Cache.GetKeysStartingWith(sessionPattern).ToList();
var activeSessions = Cache.GetAll<IAuthSession>(sessionKeys).Values;

will only get valid sessions, that are valid until they expire or client logouts (which doesn't reflect whether he is onlline or not).


Solution

  • If you're referring to Server Events subscriptions, their lifetimes are completely unrelated to User Sessions. A Server Event subscription just represents a long-lived HTTP connection to the Server Events /event-stream which may or may not be from an Authenticated User.

    The way to find out active connected users is to call /event-subscribers.

    Inside ServiceStack, all information available on Server Event subscriptions is accessible through the IServerEvents dependency, e.g. To find out all active subscriptions for a user you can call GetSubscriptionInfosByUserId()