【问题标题】:What is the impact of F5 loadbalancer on session timeout in an asp.net mvc2 appF5负载均衡器对asp.net mvc2应用程序中的会话超时有什么影响
【发布时间】:2013-06-14 16:37:07
【问题描述】:

我已经使用以下文章在 asp.net mvc2 应用程序中实现了显示会话超时的警报消息,并根据要求进行了一些自定义:

http://fairwaytech.com/2012/01/handling-session-timeout-gracefully/

以及以下会话状态模式:

<sessionState mode="SQLServer" sqlConnectionString="Data Source=StudentsDB;User ID=xxxxxxx;Password=xxxxxxx;Integrated Security=False;MultipleActiveResultSets=True" allowCustomSqlDatabase="true" cookieless="false" timeout="30" compressionEnabled="true" sqlCommandTimeout="240" />

表单超时 = 15 和会话超时 = 30

应用程序在我的开发和开发环境中运行良好(两个环境中都没有负载均衡器。

当我在有 F5 负载均衡器配置可用的 QA 和暂存环境中部署应用程序时,它开始表现得很奇怪。

对于一些用户来说,警报弹出来了,而其他一些用户根本不出现,有时它会自动注销。

该功能运行不正常且行为怪异。

F5 负载均衡器上没有启用粘性会话。

在 Global.asax.cs 文件中,我有以下代码:

protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        Only access session state if it is available
        if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState)
        {
            //If we are authenticated AND we don't have a session here.. redirect to login page.
            HttpCookie authenticationCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            if (authenticationCookie != null)
            {
                FormsAuthenticationTicket authenticationTicket = FormsAuthentication.Decrypt(authenticationCookie.Value);
                if (!authenticationTicket.Expired)
                {
                    //of course.. replace ANYKNOWNVALUEHERETOCHECK with "UserId" or something you set on the login that you can check here to see if its empty.
                    if (Session["IsSessionValid"] == null)
                    {
                        //This means for some reason the session expired before the authentication ticket. Force a login.
                        FormsAuthentication.SignOut();
                        Response.Redirect(FormsAuthentication.LoginUrl, true);
                        return;
                    }
                }
            }
        }            
    }

我试图检查我的开发和开发环境中的代码和所有东西,但没有发现任何东西。 谁能帮我了解上述问题的可能原因?

感谢和问候, 桑托什库马尔帕特罗

【问题讨论】:

    标签: jquery asp.net-mvc-2


    【解决方案1】:

    为了解决问题,我要求基础架构人员停止服务器并保持另一台服务器正常运行。在验证问题时,我们发现会话超时警告功能按预期工作。通过这个,我确保 F5 负载均衡器对会话超时功能没有影响。经过分析,我发现我在 web.config 中没有 machinekey 标签,并且在浏览了一些文章后,如下所述:

    http://aspalliance.com/383_SQL_Server_Session_State_on_a_Web_Farm http://www.hanselman.com/blog/LoadBalancingAndASPNET.aspx http://dotnet.dzone.com/news/aspnet-and-load-balancing

    我包含了 machinekey 标记并准备了包并将其部署在两台服务器上,然后再次验证了功能。我发现该功能按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-27
      • 1970-01-01
      • 2019-04-29
      • 2017-04-24
      • 1970-01-01
      相关资源
      最近更新 更多