Kicking users from Sitecore

This is a small xmas special, and a obscure one. Not many people needs to kick users from Sitecore programatically. But if you do you must use the DomainAccessGuard class. The DomainAccessGuard class controls the actual sessions for users that are logged into Sitecore.

This small class allows you to get a list of all current sessions (all users currently logged in), and to kick (log out) any user. I have developed it together with iStern, and you can see iStern’s solution on his blog.

using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sitecore.Web.Authentication;

namespace MyNamespace
{
  /// <summary>
  /// Repository for currently logged in sessions
  /// </summary>
  public class SessionsRepository
  {
    /// <summary>
    /// Gets the user sessions sorted with the most active users at the top
    /// </summary>
    /// <returns></returns>
    public IEnumerable<DomainAccessGuard.Session> GetUserSessions()
    {
      return DomainAccessGuard.Sessions.OrderByDescending(s => s.LastRequest);
    }

    /// <summary>
    /// Kicks the user session.
    /// </summary>
    /// <param name = "sessionID">The session ID.</param>
    public void KickUserSession(string sessionID)
    {
      DomainAccessGuard.Kick(sessionID);
    }
  }
}

Merry christmas, and happy Sitecore coding.

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in c#, Sitecore 6 and tagged , , . Bookmark the permalink.

One Response to Kicking users from Sitecore

  1. Sasha says:

    And just in case – Sitecore interface (Sitecore 8 specifically):
    [your hostname]/sitecore/client/Applications/LicenseOptions/StartPage

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s