This article will cover the following topics:
- Show the alert message before the session timeout.
- The user will have an option to extend or continue with the current session or he can log out from the site.
For this article I have used the jQuery plug-in, timeout-dialog.js.
Example: Timeout-Dialog.js Example
Documentation: timeout-dialog.js
Well I simply have the necessary code and I am not explaining the code here. I am mainly focusing on the example and you can download the attachment for that.
Features
- This is free and you have right to change this code.
- You can use this with a master page and Ajax update panel as well.
- You can customize all the messages and logs.
- You can apply the styles and themes to the confirm window.
CODE
Web.Config File
You need to set the session timeout in the web.config file as below:
Default.aspx file
Now you need to add the jQuery code to the page. See the following one:
![JQuery code in you page]()
Here setTimeout() will run in the background and $.timeoutDialog() will show the popup box.
Default.aspx.cs file
Here I am calling the Timer() function from my .cs file using ScriptManager. See the following code:
$.timeoutDialog() method parameters
You can see the following link:
Timeout-Dialog.jsEXAMPLE
When you run the project, it will show the “new Session”.
![new Session]()
After 2 minutes, it will display the confirm window as below:
![After 2 min display confirm window]()
When you click on “Yes, Keep me signed in”, then it will not reset the session. It will use the same session.
![session]()
Again after 2 min, it will again show the same message.
![message]()
If you click on “No, Sign me out”, then it will automatically redirect to another page and your session will be destroyed.
![destroyed session]()
New theme to confirm window:
![New theme to confirm window]()
Please provide your feedback.