2010-04-26 70 views
0

我正在使用由.NET asp/C#代码驱动的网站。客户端要求会话有25分钟的超时时间。但是,有时会使用该网站,并且用户长时间保持连接状态(超过25分钟)。 Session_End中被触发:如何避免由于超时造成的HttpException

protected void Session_End(Object sender, EventArgs e) 
{ 
    Hashtable trackingInformaiton = (Hashtable)Application["trackingInformation"]; 
    trackingInformaiton.Remove(Session["trackingID"]); 
} 

用户以后返回了一段时间,但是当他们与网站互动,他们得到一个错误,我们得到这个电子邮件通知:

User: Unauthenticated User

Error: System.Web.HttpException

Description: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request...

的的说明问题的一部分堆栈跟踪为System.Web.UI.Control.AddedControl。显然,服务器已经丢弃了会话数据,并且正在发送新数据,但客户端正试图处理旧数据。因此,错误"the control tree into which viewstate is being loaded [doesn't] match the control tree that was used to save the viewstate during the prevoius request."

所以这里的问题。如果强制如何在连接超时时指示用户的浏览器重定向到“您已注销”屏幕? (这是我应该添加到Session_End方法吗?)

回答

1

更简单的是使用Html元标记“刷新”。以下行将在页面加载5分钟后触发:

<meta http-equiv="refresh" content="300;url=http://domain.org/Logout.aspx" /> 

也许这就是您需要的。

+0

+1这可能是最简单的选择。谢谢。 – 2010-07-22 20:12:37

2

我认为你需要使用一些客户端脚本来做到这一点。尽管Session_End会触发,但Web服务器无法实际传递会话超时消息给浏览器,而无需用户首先执行一些操作(即发送请求)。因此,您必须有一些定时的客户端脚本启动该事件。

1

类似于javascript的setTimeout函数。

例如 in page onload function

setTimeout(“redirect()”,1500000); // 25分钟超时

如果您的网页上有任何AJAX,则应在您的新内容加载时清除超时并重新启动。