【问题标题】:Refresh server side session when using Ajax Updatepanel使用 Ajax Updatepanel 时刷新服务器端会话
【发布时间】: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 页面以保持会话处于活动状态?

我已经尝试了链接herehere,但我都没有运气。任何帮助是极大的赞赏。

【问题讨论】:

    标签: javascript asp.net session updatepanel


    【解决方案1】:

    您没有指定您在哪个服务器操作系统上,但可能是应用程序池在某个时间间隔后正在回收。

    【讨论】:

    • 是的,对不起,我忘了提。我使用的是 Windows Server 2008。我已经检查了该设置,并将其设置为默认设置,如上所示。对于临时修复,我删除了更新面板和触发器,它还没有不正确地超时。不过感谢您的想法。
    猜你喜欢
    • 2019-01-10
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    • 2017-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多