2

セッションの終了に問題があります。「WebForms.asax」セッションのボタンをクリックすると、常に0から1分の時間がカウントされます(このボタンをクリックすると、セッションは終了しません)。すべてのセッションを終了するために 1 分間の値を指定しましたが、Web サイトをクリックしないと機能します。どこに問題があるか知っていますか?

ここでセッションを開始します。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Session_Test
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["UserAuthentication"] = "dddd";
            TypSession.InnerHtml = "<a href='WebForm1.aspx'>sdsds</a>";
        }
    }
}

別の Web サイト (WebForm1.aspx):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Session_Test
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            example.InnerHtml = Session["UserAuthentication"].ToString()+"         "+ Session.Timeout.ToString();;
        }

        protected void Unnamed1_Click(object sender, EventArgs e)
        {
            Response.Redirect(Request.RawUrl);
            Session.Abandon();

        }
    }
}

グローバル.asax

 void Session_Start(object sender, EventArgs e)
        {
            Session.Timeout = 1; 
        }

        void Session_End(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:51888/Default.aspx");
        }
4

1 に答える 1

2
Response.Redirect(Request.RawUrl);

応答を終了します。次の呼び出しと同じです。

Response.Redirect(Request.RawUrl, true);

ここで、bool は応答の停止を表すため、Session.Abandon() が呼び出されることはありません。リダイレクト後に Session.Abandon() を実行したい場合は、リダイレクトを false で呼び出す必要があります。

Response.Redirect(Request.RawUrl, false);

MSDN をリダイレクト

于 2013-01-31T12:06:29.263 に答える