ASP.NET MVC 學習 --- 第七課(在非正常關閉IE之後,自動清除資料庫中的登陸資訊)
使用者Logon之後,我們可以在logoff裡面寫一些方法幫助我們清理資料庫中的一些資料。
但是如果使用者是非正常Logoff,而是直接關閉IE,如何去自動的清理資料庫中的資料吶。這裡是用session_end方法
方法一:
在Web.Config裡面
<sessionStatemode="InProc"stateConnectionString="tcpip=127.0.0.1:42424"sqlCommandTimeout="60"cookieless="false"timeout="2"/>
在global.asax.cs檔案裡面
protectedvoid
Session_Start(
{
Session["startValue"] = 0;
}
protectedvoid Session_End(Object sender, EventArgs e)
{
//log off 的一些操作
}
方法二:
<scripttype="text/javascript">
window.onbeforeunload = logoff;
function
if (window.event.clientX > document.body.clientWidth-50 && event.clientY < 0 || event.altKey){
jQuery.post(
"/Account/LogOff", function () { });
}
}
</script>