【发布时间】:2014-04-03 15:44:07
【问题描述】:
我在使用更新面板时刷新服务器会话时遇到问题。我有三个触发按钮。
<asp:UpdatePanel ID="TrackingUpdatePaenl" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnPopulate" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnGo" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnTopUpdate" EventName="Click" />
</Triggers>
<ContentTemplate>
//GridView that is updated by the triggers
</ContentTemplate>
</asp:UpdatePanel>
我遇到的问题是 ServerState 会话在异步回发后不会自行刷新。在我的 webconfig 中,我将会话状态和表单身份验证都设置为 60 分钟超时。发生的情况是,即使页面处于活动状态,页面也会在 60 分钟后由于不活动而超时。一旦他们的服务器端会话超时,我正在使用这个 javascript 来重定向用户......
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
// Handle the session timeout
string sessionExpiredUrl = Request.Url.GetLeftPart(UriPartial.Authority) + "/DealLog/Account/SessionExpiredRedirect.aspx";
StringBuilder script = new StringBuilder();
script.Append("function expireSession(){ \n");
script.Append(string.Format(" window.location = '{0}';\n", sessionExpiredUrl));
script.Append("} \n");
script.Append(string.Format("setTimeout('expireSession()', {0}); \n", this.Session.Timeout * 60000)); // Convert minutes to milliseconds
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "expirescript", script.ToString(), true);
}
上面的代码在我的站点主页面加载中。这在不使用更新面板时效果很好。
用户抱怨即使他们正在使用该页面,它也会在 60 分钟后超时。我印象中解决这个问题的方法是使用 javascript 来更新会话。我在互联网上找到的所有内容都使用 javascript 来执行此操作,但它们会在计时器上调用服务器,即使页面处于非活动状态,页面也会保持活动状态。这不是我需要的解决方案。如何在这些按钮单击时刷新服务器会话?一旦用户点击按钮,调用 javascript 来调用另一个 aspx 页面以保持会话处于活动状态?
【问题讨论】:
标签: javascript asp.net session updatepanel