session相关问题
private void Page_Load(object sender, System.EventArgs e)
{
Response.AddHeader("Refresh",Convert.ToString((Session.Timeout * 60) + 5));
if(Session[“IsUserValid”].ToString()==””)
Server.Transfer(“Relogin.aspx”);
}
在page.load事件中,加入response.addheader方法,当session过期失效后的5秒,页面就会自动刷新,这
个时候,判断到session失效了,之后系统自动跳转了
如何使得关闭页面立即结束会话session
Session_OnEnd() will not be called if the user just closed his window and will be called when the Session times out
1. in your page (not always work, for example, when the user browser away from your site)
<script language="javascript">
function window.onunload()
{
if (event.clientX < 0 && event.clientY < 0)
window.open("logout.aspx","logout");
}
</script>
in logout.aspx, call
<%
Session.Abandon()
%>
2. use a method which doesn't use Session_OnStart/Session_OnEnd, for example, keep a DataTable in an Application variable and record users' last access time, the DataTable is checked every time a user sends a request, if the access time for any user was 10 minutes ago, you remove the user from the DataTable
但是我发现这种关闭页面即关闭SESSION的方法很不实际.