I want to implement timeout in sharepoint site. I want to popup a message to user every 30 min if he is idle on the site. A continue button should be coming in popup and if he clicks ok he should be able to continue to the site.Iif he doesnot click continue he should be logged out of site in sometime. how to implement this? I am using ADFS and STS authentication for my web application.

2 Answers 2


I would presume that you need to set a session state time out.

The Timeout property can be set in the Web.config file for an application using the timeout attribute of the sessionState configuration element, or you can set the Timeout property value directly using application code.

The Timeout property cannot be set to a value greater than 525,600 minutes (1 year). The default value is 20 minutes.

The following code example sets the timeout session attribute to 30 minutes in the Web.config file.

      timeout="30" />


you need to set the above greater than 30 min otherwise youll be asked for login ;) , if it still does it than you would also need to do it in IIS!

now to show the message follow this tut from codeproject:

Since seeing is believing, let's start with the master page and the visual components. In the HTML, our div tag divTimeoutWarning contains the initial warning message and a button. We give it a position of Fixed to be sure it is positioned relative to the browser window and not subject to scrolling. We also have a ScriptManager control on the page so we can use an UpdatePanel. This is the regular non-visual control available in the Toolbox in the "AJAX Extensions" group.

Now looking at the JavaScript, our first function BodyOnLoad() registers interrupts which will be activated before, and when, the session expires. Next, ShowSessionTimeoutWarning() simply gets a reference to the div and changes the display attribute to inline so the div will appear. The function ShowSessionExpiredNotification() is activated if the user fails to acknowledge the initial warning. It can be used to show a new message or it can be used to redirect the user to any page via the JavaScript window.location property. When the user does press the button to keep his session alive, a very simple AJAX request is sent to the server. When the server receives this, it automatically refreshes the session window. We use a client side click function ResetClientSideTimers() to re-hide the div tag by setting its display attribute to none, and we reset the timeouts for our warning functions so we can repeat the process all over again.

<%@ Master Language="C#" AutoEventWireup="true" 
    CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Master Page</title>

    <script type="text/javascript" language="javascript">

        //Set timeouts for when the warning message
        //should be displayed, and what should happen 
        //when the session actually expires.
        function BodyOnLoad()
            setTimeout('ShowSessionTimeoutWarning()', '<%=iWarningTimeoutInMilliseconds%>');
            setTimeout('ShowSessionExpiredNotification()', '<%=iSessionTimeoutInMilliseconds%>');

        //Notify the user that his session is ABOUT to expire.
        //Do so by making our warning div tag visible.
        function ShowSessionTimeoutWarning()
            var divSessionTimeoutWarning = 

            divSessionTimeoutWarning.style.display = 'inline';

        //Notify the user that his session HAS expired.
        function ShowSessionExpiredNotification()
            var divSessionTimeoutWarning = 

            //Send the user to a new page.
            window.location = '<%=sTargetURLForSessionTimeout%>';

            //To tell the user that his session has expired, WITHOUT redirecting, 
            //remove the above line, and uncomment this section:
            ////Re-use the existing label, but change the text.
            //var lblSessionWarning = document.getElementById('<%=lblSessionWarning.ClientID%>');
            //lblSessionWarning.innerText = 'Your session has expired. You are SOL.';
            ////Hide button.
            //var btnContinueWorking = document.getElementById('<%=btnContinueWorking.ClientID%>');
            //btnContinueWorking.style.display = 'none';

        function ResetClientSideSessionTimers()
            var divSessionTimeoutWarning = 
            divSessionTimeoutWarning.style.display = 'none';

            //Reset timers so we can warn the user the NEXT time the session is about to expire.
            setTimeout('ShowSessionTimeoutWarning()', '<%=iWarningTimeoutInMilliseconds%>');
            setTimeout('ShowSessionExpiredNotification()', '<%=iSessionTimeoutInMilliseconds%>');

    <asp:ContentPlaceHolder ID="head" runat="server">
<body onload="BodyOnLoad()">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <%--In a real application, use a CSSClass and set these 
                 display properties in a CSS file, not inline.--%>
        <div id="divSessionTimeoutWarning" runat="server" 
                  style="position: fixed; left: 250px; top: 100px; 
                         background-color: Yellow; border-style: solid">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <asp:Label ID="lblSessionWarning" runat="server" 
                       Text="Warning.  Your server session is about to expire due to inactivity."
                    <br />
                    <asp:Button ID="btnContinueWorking" runat="server" Text="Continue Working" 
                       OnClick="btnContinueWorking_Click" />
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

Master Page C# Code-Behind

Now let's take a look at the code-behind for the master page. First off, we use Session.Timeout to pull the timeout value from the web.config file. Since this setting is in minutes (20 by default), and since our client-side functions expect milliseconds, we do a little math and store the results in two public variables so they can be accessed from the master page's ASPX. We set the display attribute for the div to "none" so it isn't displayed when the page first comes up, and we do this in C# so that the div is visible in Visual Studio at design time. The btnContinueWorking_Click() method is called by our keep-alive button which is inside an UpdatePanel. Receipt of the AJAX message itself will refresh the session, so the Click method doesn't need to run any code.

using System;
using System.Configuration;

namespace WebApplication1
    public partial class Site1 : System.Web.UI.MasterPage
        //Public values here can be late-bound to javascript in the ASPX page.
        public int iWarningTimeoutInMilliseconds;
        public int iSessionTimeoutInMilliseconds;
        public string sTargetURLForSessionTimeout;

        protected void Page_Load(object sender, EventArgs e)
            //In a real app, stuff these values into web.config.
            sTargetURLForSessionTimeout = "Error.aspx?Reason=Timeout";
            int iNumberOfMinutesBeforeSessionTimeoutToWarnUser = 1;

            //Get the sessionState timeout (from web.config).
            //If not set there, the default is 20 minutes.
            int iSessionTimeoutInMinutes = Session.Timeout;

            //Compute our timeout values, one for
            //our warning, one for session termination.
            int iWarningTimeoutInMinutes = iSessionTimeoutInMinutes - 

            iWarningTimeoutInMilliseconds = iWarningTimeoutInMinutes * 60 * 1000;

            iSessionTimeoutInMilliseconds = iSessionTimeoutInMinutes * 60 * 1000;

            if (!this.IsPostBack)
                //Don't show the warning message div tag until later.
                //Setting the property here so we can see the div at design-time.
                divSessionTimeoutWarning.Style.Add("display", "none;");

        protected void btnContinueWorking_Click(object sender, EventArgs e)
            //Do nothing. But the Session will be refreshed as a result of 
            //this method being called, which is its entire purpose.

    } //class
} //namespace




Set the customConfiguration.DefaultTokenLifetime = new System.TimeSpan(8, 0, 0); Refer the link : http://blogs.perficient.com/microsoft/2010/12/sliding-sessions-with-sharepoint-2010-and-claims/

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.