Asp.net会话终止

本文关键字:终止 会话 net Asp | 更新日期: 2023-09-27 18:23:40

当我终止会话并通过它的url再次返回时,它会显示我的用户名。我试过session.abandon()session.RemoveAll()session.Clear()。。。。我们将不胜感激。提前谢谢。嘿,伙计们,谢谢。但当我通过浏览器返回按钮时,代码运行良好,但在手动粘贴URL时不起作用。这是代码

public partial class products : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["full_name"] == null)
        {
            Response.Write("<script language='javascript'>alert('Your are Logged out.Please sign In to Continue.');location='Log-In.aspx'</script>");   
        }
        else
        {
            Response.Write("hi "+Session["full_name"].ToString());
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session.Remove("full_name");
        Session.Abandon();
        Response.Write("<script language='javascript'> alert('logged out successfully');location='Log-In.aspx'</script>");
    }
}

希望它能帮助

Asp.net会话终止

您不想注销用户吗?在这种情况下,取消会话对你来说是行不通的。如果使用Forms Authentication,则可以执行FormsAuthentication.SignOut方法来执行此操作。

使用此代码。希望能解决问题

//old authentication, kill it
FormsAuthentication.SignOut();
//or use Response.Redirect to go to a different page
FormsAuthentication.RedirectToLoginPage("Session=Expired");
HttpContext.Current.Response.End();

将此代码放在您要注销的页面的Load事件上。

    Response.Clear();
    Response.Cache.SetExpires(DateTime.Now.AddMinutes(-1));
    Response.Cache.SetNoStore();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);

并调用问题中提到的任何上述方法来终止会话。