简体   繁体   中英

session timeout message popup before 5mins of actual session timeout?

I need to show a timeout popup window 5 mins before the session timeout. So far I have got

<script type="text/javascript">

       function Timeout(intMilsec) {
               setTimeout("window.focus(); alert('Your session will timeout in 5
minutes')", intMilliseconds);
       }
</script>

And in c#

 if(Session["id"] != null)
  {

      int time = (Session.Timeout - 5) * (60 * 1000);
      Img.Attributes.Add("onload", "Timeout(" +time + ");");
  }
  else
      Img.Attributes.Remove("onload");

The popup not showing up before 5mins and never. I need to know if I am missing any settings

I didn't understand why you used the image's onload event, but anyway...

You can use Page.ClientScript.RegisterStartupScript(typeof(string), "SessionTimeout", "setTimeout(" + time + ")", true); to call a script on the page loading.

Is your JavaScript working? Have you tried it separately? I tried the exact same code you posted and it didn't work. Try this one:

function Timeout(intMilsec) {
    setTimeout(function() { alert('Your session will timeout in 5 minutes'); }, intMilsec);​​​​​​​​​​​​
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM