Duplicating a session

My eventual goal is to persist a session across executions of a Winforms app by saving the session Ids from the JsonServiceClient, but it is not working. The code below is an attempt to duplicate what you do in some of your Auth tests, but the second call to my service AppConstants is returning a 401: Unauthorized. (the first call against oldClient works)

 var uri = "http://localhost/dvsvc";
 var oldClient = new ServiceStack.JsonServiceClient(uri);
 var v = oldClient.Send<ServiceStack.AuthenticateResponse>(new ServiceStack.Authenticate()
 {
     UserName = "mtagliaf",
     Password = "YourPasswordHere",
     provider = "DV",
     RememberMe = true
 });

 var aOld = oldClient.Get(new AppConstants());
 Console.WriteLine(aOld.ScoutAbbr);  //works

  var newClient = new ServiceStack.JsonServiceClient(uri);
  newClient.SetSessionId(oldClient.GetSessionId());
  newClient.SetPermanentSessionId(oldClient.GetPermanentSessionId());

  var aNew = newClient.Get(new AppConstants());  //401: unauthorized
  Console.WriteLine(aNew.ScoutAbbr);

If you use RememberMe then the Server Session will be saved against the ss-pid Permanent Session Id which also requires setting the ss-opt cookie to “perm”, e.g:

client.SetCookie("ss-opt", "perm");

Alternatively if you don’t use RememberMe=true you’d just need to copy over the SessionId.

1 Like