用戶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(Object sender, EventArgs e)
{
Session["startValue"] = 0;
}
protectedvoid Session_End(Object sender, EventArgs e)
{
//log off 的一些操作
}
方法二:
<script type="text/javascript">
window.onbeforeunload = logoff;
function logoff() {
if (window.event.clientX > document.body.clientWidth-50 && event.clientY < 0 || event.altKey){
jQuery.post(
"/Account/LogOff", function () { });
}
}
</script>