Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi i am trying to open popup session expire before 15 min but when i set 120 min in webconfig then minutes is showing wrong minutes

so please help me

What I have tried:

JavaScript
$(function () {
            $("#dialog").dialog({
                autoOpen: false,
                modal: true,
                title: "Session Expiration Warning",
                buttons: {
                    "Extend Session": function () {
                        ResetSession();
                    },
                    Logout: function () {
                        CloseSession();
                    },
                    Close: function () {
                        $(this).dialog('close');
                    }
                }
            });
        });
        function SessionExpireAlert(timeout) {
            var minutes = timeout / 1000/60-1;
            var seconds = 59;
            $('#seconds').html(minutes + ':' + seconds);
            var interval = setInterval(function () {

                //var timer2 = $("14:59");
                //var timer = timer2.split(':');
                //by parsing integer, I avoid all extra string processing
                //var minutes = 14;
                //var seconds = 59;
                --seconds;
                minutes = (seconds < 0) ? --minutes : minutes;
                if (minutes < 0) clearInterval(interval);
                seconds = (seconds < 0) ? 59 : seconds;
                seconds = (seconds < 10) ? '0' + seconds : seconds;
                $('#seconds').html(minutes + ':' + seconds);
            }, 1000);
            setTimeout(function () {
                //Show Popup before 900 seconds of timeout.//
                $('#dialog').dialog('open');
            }, 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";
        };

------------------------------------------------------------------------------
C#
Response.Cache.SetCacheability(HttpCacheability.NoCache);
               if (!this.IsPostBack)
               {
                   Session["Reset"] = true;
                   Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
                   SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
                   var timeout = section.Timeout.TotalMinutes * 1000 * 60;
                   ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
               }

------------------------------------------------------------------------------
XML
<sessionstate mode="InProc" timeout="120">
Posted
Updated 1-Jun-21 0:52am
v2

1 solution

This seems like it's related to the previous question you asked here[^]

When you say it's showing incorrect minutes, what do you mean? What value are you seeing on the screen, and what value are you expecting to see? Have you debugged both the C# code (to ensure that the timeout value is being pulled in correctly) and tried debugging the Javascript code to see whether the values you're getting back are expected?

You asked me in the previous question to provide you with the code to change but I can't do that unless we have an idea of what isn't working exactly. I did mention before that relying on setTimeout/setInterval can be tricky because there's no guarantee they'll fire on the exact timeout.
 
Share this answer
 

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