Show warning in popup just before Session Ends

On many websites we see some popup like you your session will end in 2 mins, specially in Banking website we see this kind of popup. So lets see how can we implement this functionality.

Step 1: Set Timeout in SessionState tag in Web.Config file.

<sessionState mode=”InProccustomProvider=”DefaultSessionProvidertimeout=”3>

Step 2: Add a key in Web.Config in AppSetting for Warning time, time after which you want to show popup.

<appSettings>
    <add key=”SessionTimeOutWarningTimevalue=”2/>
 </appSettings>

Step 3: In your master page, write below script code. The key this of this approach is, as soon as you load a page it sets a Timeout function, so if you are ideal for that much time then it’ll prompt you. And when you reload the page or move to some other page then master page also reloads so it’ll reset the whole code, so whatever time you spent on previous page will not impact on new page. Whole thing will start from zero.

<script type=“text/javascript”>
var sessionTimeOut = <%= Session.Timeout %>;

var sessionWarningTime = “<%=

ConfigurationManager.AppSettings[“SessionTimeOutWarningTime”] %>”;

var timeOutInMiliSeconds = (parseInt(sessionWarningTime ) * 60 * 1000);

setTimeout(“sessionTimeOutShowPopup()”, timeOutInMiliSeconds);

function sessionTimeOutShowPopup() {

alert(“Session will expire in “ +

                       (parseInt(sessionTimeOut) – parseInt(sessionWarningTime ))

          );

};
</script>

Advertisements

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