1

私はウェブアプリを持っていて、ページでのセッションタイムアウトとユーザーインタラクションで、これはホーム/ランディングページにリダイレクトする必要があります

ネットで見つけた解決策

1) アプリケーションのすべての aspx ページの page_load でのセッション チェック。2) global.asax のセッション開始時のコード

public void Session_Start    
{
        Response.Redirect("home.aspx");
        // or Server.Transfer("home.aspx");
}

私は 2 番目のオプションを選択します。1) 私が正しい方法をとっているのか、それともより良い解決策があるのか​​を教えてください。2) 2 番目のオプションで、Response.Redirect または Server.Transfer を使用するかどうか

-ありがとう

4

2 に答える 2

5

私は最初のものに行き、セッションをチェックします.....

マスター ページの OnInit メソッドに次のコードを記述すると、タックが簡単になります。

    /// <summary>
    /// Check for the session time out 
    /// </summary>
    /// <param name="e"></param>
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        if (Context.Session != null)
        {
            //check whether a new session was generated
            if (Session.IsNewSession)
            {
                //check whether a cookies had already been associated with this request
                HttpCookie sessionCookie = Request.Cookies["ASP.NET_SessionId"];
                if (sessionCookie != null)
                {
                    string sessionValue = sessionCookie.Value;
                    if (!string.IsNullOrEmpty(sessionValue))
                    {
                        // we have session timeout condition!
                        Response.Redirect("Home.aps");
                    }
                }
            }
        }
    } 
于 2011-06-02T04:41:16.113 に答える
2

JavaScript を使用しないのはなぜですか。setTimeout次のような方法を使用できます

<script type="text/javascript">
setTimeout('window.location = "home.aspx"', 3000);
</script>

上記の js コード ブロックをページ ヘッダーに挿入します。3000 はセッション タイムアウトです。

于 2011-04-09T13:37:11.347 に答える