Uncategorized

The context has expired and can no longer be used.

Executed the following script and noticed the following error

The context has expired and can no longer be used.

The Script

Add-PSSnapin Microsoft.SharePoint.PowerShell;
$CS = [Microsoft.SharePoint.Administration.SPWebService]::ContentService;
#TokenTimeout value before
$CS.TokenTimeout;
$CS.TokenTimeout = (New-TimeSpan -minutes 2);
#TokenTimeout value after
$CS.TokenTimeout;
$CS.update();
$STSC = Get-SPSecurityTokenServiceConfig
#WindowsTokenLifetime value before
$STSC.WindowsTokenLifetime;
$STSC.WindowsTokenLifetime = (New-TimeSpan -minutes 2);
#WindowsTokenLifetime value after
$STSC.WindowsTokenLifetime;
#FormsTokenLifetime value before
$STSC.FormsTokenLifetime;
$STSC.FormsTokenLifetime = (New-TimeSpan -minutes 2);
#FormsTokenLifetime value after
$STSC.FormsTokenLifetime;
#LogonTokenCacheExpirationWindow value before
$STSC.LogonTokenCacheExpirationWindow;
#DO NOT SET LogonTokenCacheExpirationWindow LARGER THAN WindowsTokenLifetime
$STSC.LogonTokenCacheExpirationWindow = (New-TimeSpan -minutes 1);
#LogonTokenCacheExpirationWindow value after
$STSC.LogonTokenCacheExpirationWindow;
$STSC.Update();
IISRESET

Script source –¬†https://www.vioreliftode.com/index.php/active-directory-security-groups-and-sharepoint-claims-based-authentication

To fix this issue

run IISRESET on web front end server

Other possible causes could be

http://expertsharepoint.blogspot.com.au/2014/10/the-context-has-expired-and-can-no.html?_sm_au_=iVV4NSWGQJV1jsQM

http://blog.robgarrett.com/2012/09/23/the-context-has-expired-and-can-no-longer-be-used/