Click here to Skip to main content
15,611,207 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if (!this.IsPostBack)
Session["Reset"] = true;
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
int timeout = (int)section.Timeout.TotalMinutes * 1000 * 60;
ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);

<script type="text/javascript">
       $(function () {
               autoOpen: false,
               modal: true,
               title: "Session Expiration Warning",
               buttons: {
                   "Extend Session": function () {
                   Logout: function () {
                   Close: function () {
       function SessionExpireAlert(timeout) {
           var seconds = timeout / 1000;
           setInterval(function () {
           }, 1000);
           setTimeout(function () {
               //Show Popup before 900 seconds of timeout.//
           }, timeout - 900 * 1000);
           setTimeout(function () {
               window.location.href = "../../../User/SessionExpired";
           }, timeout);
       function ResetSession() {
           //Redirect to refresh Session.
           window.location = window.location.href;
       function CloseSession() {
           //Redirect to refresh Session.//
           window.location.href = "../../../User/SessionExpired";

What I have tried:

when internet connection slow then pop up open before 900 second how to open pop up exact 900 seconds
Updated 25-May-21 1:05am

1 solution

One thing to bear in mind is that Javascript for a particular website runs on one thread and is not inherently asynchronous. Things like async methods or Promise run within one thread and simply get called when the page is free to do so.

If you have particularly intensive background Javascript tasks running this can block things like timeouts, intervals and the invocation of promises. There's no guarantee that the timeout or interval will trigger at exactly 900 seconds as you need, but could be a few seconds before or after.

Another thing of interest as well is that setTimeout uses 32-bit signed integers for the interval, so you need to make sure that the timeout doesn't exceed 2,147,483,647.
Share this answer
Member 12183079 27-May-21 3:14am    
Hi Sir
please write a code where i could change

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900