Loading...
Area: Episerver Tracking
Applies to versions: 1.6 and higher

Configure session durations

Recommendations [hide]

This topic describes how to configure session durations using the EPiServer.Session package, available with tracking services for the Episerver platform.

How it works

The EPiServer.Session NuGet package provides the <string> SessionId for other Episerver tracking services. A session expires after 30 minutes (by default) if clients have no activity.

You can get the SessionId by invoking EPiServer.Session.ISessionService.GetCurrentSessionId().

The default DefaultSessionService gets and stores the SessionId in the client’s browser cookie (with Max-Age 1800 second (30 minutes)), the cookie, if existed, is renewed on every server request.

You can change cookie duration in SessionOptions, the Duration is the seconds before the cookie expires. The following example (from an Alloy site) shows how to set the duration in class DependencyResolverInitialization:

public void ConfigureContainer(ServiceConfigurationContext context)
  {
    //Implementations for custom interfaces can be registered here.
    context.ConfigurationComplete += (o, e) =>
      {
        //Register custom implementations that should be used in favour of the default implementations
        context.Services.AddTransient<IContentRenderer, ErrorHandlingContentRenderer>()
        .AddTransient<ContentAreaRenderer, AlloyContentAreaRenderer>()
        .AddSingleton(new SessionOptions {Duration = 10});
      };
  }
Do you find this information helpful? Please log in to provide feedback.

Last updated: Mar 18, 2019

Recommendations [hide]