View(_Layout)
<script> inactivityTime (); function inactivityTime () { var t; window.onload = resetTimer; // DOM Events window.onmousemove = resetTimer; window.onkeypress = resetTimer; //window.onmousedown = resetTimer; // catches touchscreen presses //window.onclick = resetTimer; // catches touchpad clicks //window.onscroll = resetTimer; // catches scrolling with arrow keys function logout() { //alert("You are now logged out.") window.location = "/Account/LogOffAuto"; } function resetTimer() { clearTimeout(t); var sessionTimeoutWarning = 10; //min var sTimeout = parseInt(sessionTimeoutWarning) * 60 * 1000; t = setTimeout(logout, sTimeout); // 1000 milisec = 1 sec } }; </script>
Controller
public ActionResult LogOffAuto() { Session["User"] = null; //it's my session variable Session.Clear(); Session.Abandon(); FormsAuthentication.SignOut(); //you write this when you use FormsAuthentication return RedirectToAction("Login", "Account"); }
David Kung 2017/07/20
很實用,謝謝。
回覆刪除