Surendra Sharma

Surendra Sharma

Search This Blog

Thursday, March 23, 2017

How to expire Sitecore session forcefully

In one of our project, I have to forcefully expire the Sitecore session so that it flush the data to MongoDB.

For this either you can restart IIS or start-stop your website. But this action require you to login into the system. But what if you are accessing Sitecore remotely or over the internet.

So I write this script which expire the session and clear the Sitecore analytics related cookies.

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
            Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", string.Empty));
            Response.Cookies.Add(new HttpCookie("SC_ANALYTICS_SESSION_COOKIE", string.Empty));
            Response.Cookies.Add(new HttpCookie("SC_ANALYTICS_GLOBAL_COOKIE", string.Empty));

I called this script as "ForceSessionEnd.aspx" and keep it in "Website" folder.

Access this script over the browser as "http://yourinstancename/forcesessionend.aspx".

After running this page, you will get latest data on mongo database.

Feel free to add more cookies as per your need.

I hope you like this Sitecore script. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)
Please leave your comments or share this script if it’s useful for you.

No comments:

Post a Comment