Microsoft's session provider model doesn't make it very easy to get at sessions from external systems. ScaleOut's .NET Core APIs aren't really designed to get at old .NET Framework session data.
Option 1
This could be accomplished under the traditional .NET Framework runtime. You'd need to use some of the low-level APIs that ship with the product (the session provider uses behind the scenes). For example:
C#:
// reference C:\Program Files\ScaleOut_Software\StateServer\DOTNET4.7.2\soss_svcdotnet.dll
using Soss.Client;
class Program
{
static void Main(string[] args)
{
const string APPLICATION_NAME = "SOSS_Session";
string sessionId = "j5mxuz3r0cetbjzxmp1rbasp";
ApplicationNamespace ns = ApplicationNamespace.GetNamespaceFor(APPLICATION_NAME);
// Create a StateServerKey that refers to the session object in question:
var sa = new SessionAccessor(sessionId);
StateServerKey sessionKey = ns.CreateKey(sa.Key.ToByteArray());
// Use a cheap DataAccessor ReadMetadata call to do a touch and reset timeout:
DataAccessor da = DataAccessor.CreateDataAccessor(sessionKey, lockWhenReading: false);
da.ReadMetadata(ReadOptions.ObjectMayNotExist);
}
}
Option 2
If you
must use .NET Core for this task then you'll need to switch the web app away from the traditional session provider that's always shipped with the main ScaleOut product suite and move to ScaleOut's newer session provider, the Scaleout.AspNet provider (
nuget,
docs). This newer session provider is built on the same Scaleout.Client library that's available to .NET Core, so interop using the
Scaleout.Client Cache API is more straightforward.
So if you switch to the newer session provider, timeouts could be reset using the
Cache class from .NET Core like this:
C#:
// reference Scaleout.Client nuget package
using Scaleout.Client;
class Program
{
static void Main(string[] args)
{
string sessionId = "j5mxuz3r0cetbjzxmp1rbasp";
// use same connection string as ScaleOut.AspNet session provider's config:
var connString = "bootstrapGateways=127.0.0.1;721";
// use same value that the session provider's "namespace" attribute uses
// (see https://static.scaleoutsoftware.com/docs/aspnet_session/Scaleout.AspNet.html#configuration ):
var cacheName = "SOSS_Session";
var gridConn = GridConnection.Connect(connString);
var cacheBuilder = new CacheBuilder<string, byte[]>(cacheName, gridConn);
// encode keys the same way as the session provider.
cacheBuilder.SetKeyEncoder(new Scaleout.Client.KeyEncoding.AspNetSessionIdEncoder(false));
var cache = cacheBuilder.Build();
// Use a cheap GetMetadata call to do a touch and reset a session's timeout:
cache.GetMetadata(sessionId);
}
}