0

次の記事を使用して、要件に従っていくつかのカスタマイズを行い、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" />

Forms timeout=15 および Sessiontimeout = 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;
                    }
                }
            }
        }            
    }

私は開発環境と開発統合環境でコードとすべてのものをチェックしようとしましたが、何も見つかりませんでした。上記の問題の考えられる理由を知るのを手伝ってくれる人はいますか?

よろしくお願いいたします。 サントッシュ・クマール・パトロ

4

1 に答える 1

0

問題のトラブルシューティングを行うために、私はインフラ担当者にサーバーの停止と他のサーバーの稼働を維持するように依頼しました。この問題を検証したところ、セッション タイムアウトの警告機能が期待どおりに機能していることがわかりました。これにより、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 タグを含めてパッケージを準備し、両方のサーバーに展開してから、機能をもう一度検証しました。機能が期待どおりに機能することがわかりました。

于 2013-06-19T07:12:16.603 に答える