用户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>