15

How to log off the SharePoint site, if the user is has been inactive for for 20 minutes? Do I need to redirect user to logout page? How would I count the idle time?

3
  • This is for an Internet facing site? Commented Feb 14, 2012 at 6:55
  • No, intranet portal. Commented Feb 14, 2012 at 9:18
  • <script type="text/javascript"> function Timeout(){ var t = setTimeout("RedirectToLogout()", 20*60000); } function RedirectToLogout(){ window.navigate("/_layouts/SignOut.aspx"); } </script> this is the js script i used tried to redirect the page to signout page, but whats happened is if i use this code in managed path like server/site it will redirect to server/_layouts/SignOut.aspx. but it has to redirect to server/site/_layouts/SignOut.aspx Commented Feb 14, 2012 at 9:23

4 Answers 4

14

You could count the idle time and redirect to signout page with javascript like this:

setTimeout(function(){
      window.location.href = _spPageContextInfo.webServerRelativeUrl + "/_layouts/signout.aspx";
}, 1200000);

Add that javascript to your .master page.

Session termination itself is obviously configured separately (see other answers). Solution above only handles redirection.

8
  • <script type="text/javascript"> function Timeout(){ var t = setTimeout("RedirectToLogout()", 20*60000); } function RedirectToLogout(){ window.navigate("/_layouts/SignOut.aspx"); } </script> this is the js script i used tried to redirect the page to signout page, but whats happened is if i use this code in managed path like server/site it will redirect to server/_layouts/SignOut.aspx. but it has to redirect to server/site/_layouts/SignOut.aspx Commented Feb 14, 2012 at 9:23
  • If you want to use the JavaScript approach, you can either grab the window.location and regex out to get the managed path, or simply use the L_Menu_BaseUrl JavaScript variable that SharePoint generates you.
    – webdes03
    Commented Feb 14, 2012 at 13:50
  • Modified script to include server relative path.
    – Jussi Palo
    Commented Feb 14, 2012 at 14:04
  • 2
    EDGE-CASE: If you have a user who has multiple tabs open, and forgets about one of his tabs, after 20 mins (or however long) that tab will log his entire session out, regardless of the activity in the other tabs.
    – James Love
    Commented Feb 14, 2012 at 20:53
  • 1
    @TomResing: Thanks for pointing that out. I was only thinking of the redirection as session expiration will occur anyway. Added clarification of this to my answer.
    – Jussi Palo
    Commented Nov 14, 2012 at 13:07
11

There is a setting located at web application general settings in the Central Admin ( Central Administration -> Application Management > Web application general settings ) which keeps the security validation for 30 mins by default and then if users tries to access the site. user will get a security prompt.

In SP2010: Central Admin ->Application Management -> Manage Web Application -> Select the specific Web application and from the Ribbon select the "General Settings" -> "General Settings"

3
  • 4
    Also note that this depends on the browser settings. For eg:- If in IE "Automatic Logon with current username and password" is checked, then you wont notice a difference even though the time out has been checked.
    – Deepu Nair
    Commented Feb 14, 2012 at 8:08
  • I am not able to access this root. do we have any root likee this.( Central Administration -> Application Management > Web application general settings ) Is that available in SP 2010 ( I fount it It there is manage web application) Commented Feb 14, 2012 at 9:57
  • I have updated my response for SP2010 Commented Feb 14, 2012 at 10:37
7

FBA? If so, you can configure this via powershell:

http://blog.petercarson.ca/Pages/SharePoint-2010-Session-Management.aspx

$sts = Get-SPSecurityTokenServiceConfig 
$sts.UseSessionCookies = $true 
$sts.FormsTokenLifetime = (New-Timespan –Minutes 2)
$sts.LogonTokenCacheExpirationWindow = (New-Timespan –Minutes 1)
$sts.Update() 
iisreset
5
<script type="text/javascript">
    function Timeout(){
        var t = setTimeout("RedirectToLogout()", 20*60000);
    }
    function RedirectToLogout(){
       var path = SP.Utilities.Utility.getLayoutsPageUrl("SignOut.aspx");
       window.navigate(path);
    }
    </script>

i have added this script in body section

<script>
    window.onload=Timeout; 
</script>

Finally this stuff works. Thanks Abi.

1
  • please call the Timeout method inside jquery document.ready Commented Feb 16, 2012 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.