gpt4 book ai didi

c# - ASP.NET global.asax end_session( session 永不结束)

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:27 25 4
gpt4 key购买 nike

我在结束 session 时遇到问题。当我单击“WebForms.asax” session 中的按钮时, session 计数时间从零到一分钟(如果我单击此按钮, session 将永远不会结束)。我给了 1 分钟的时间来结束所有 session ,当我不点击网站时它就起作用了。你知道哪里出了问题吗?

我在这里开始 session :

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>";
}
}
}

另一个网站(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");
}

最佳答案

Response.Redirect(Request.RawUrl);

会结束你的响应,这和调用一样:

Response.Redirect(Request.RawUrl, true);

其中 bool 代表停止响应,因此您的 Session.Abandon() 将永远不会被调用。如果您想在重定向后执行 Session.Abandon(),您应该使用 false 调用重定向:

Response.Redirect(Request.RawUrl, false);

Redirect MSDN

关于c# - ASP.NET global.asax end_session( session 永不结束),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14624912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com