ASP. NET implements automatic Logout

Source: Internet
Author: User

After the user logs on to the system, if no action is made, the system will automatically pop up a dialog box prompting the user to sign in again after a specified time.

The code is as follows:

<script type= "Text/javascript" >
var timer;
var wait = 20; Waiting time in minutes
Document.onmousemove = Resettimer;
function Resettimer () {
var timeoutpopup_display = document.getElementById (' Div_timeoutpopup '). Style.display;
if (timeoutpopup_display! = "Block") {
Cleartimeout (timer);
}

            timer = setTimeout ("Logout ()", 60000 * wait);  //60000 = 60 Seconds
       }
         Function logout () {
            document.getElementById (' Div_background '). style.display = ' block ';
            document.getElementById (' div_ Timeoutpopup '). style.display = ' block ';
            document.getElementById (' Expired_text '). style.display = ' block ';
            document.getElementById (' btn_logout '). Style.display = ' inline-block ';            
        }  
    </script>

Add two div to the foreground interface

<div id= "Div_background" style= "display:none; width:100%;height:100%; position:fixed;top:0px;left:0px;
Background-color: #030303; Filter:progid:DXImageTransform.Microsoft.Alpha (opacity=80); Filter:alpha (opacity=80); opacity:0.8; " >
</div>
<div id= "Div_timeoutpopup" align= "center" class= "Timeoutpopup" >
<span id= "Expired_text" style= "Font-size:14px;display:none" ><br/><br/><br/>Your session Has expired!<br/><br/><br/></span>
<input type= "button" id= "Btn_logout" value= "log-in Again" style= "Height:30px;width:100px;display:none;" onclick= " location.href= ' adminlogin.aspx ' "/>
</div>

The CSS code is as follows:

. timeoutpopup
{
Display:none;
position:fixed;
top:0; right:0; bottom:0; left:0;
width:30%;
height:25%;
Margin:auto;
padding:4px;
Border:solid 2px #999999;
Background-color: #EAEAEA;
Text-align:center;
}

Effect



ASP. NET implements automatic Logout

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.