HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Configure session durations

Describes how to configure session durations using the EPiServer.Session package, available with tracking services for the Optimizely platform.

The EPiServer.Session NuGet package provides the SessionId for other Optimizely 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});
      };
  }