繁体   English   中英

点击“ OnLoggingOut”操作后会话未结束

[英]Session not ending on click of “OnLoggingOut” action

我正在尝试使用以下代码注销网站上的会话。 但是,当我单击注销按钮时,似乎没有任何反应。

这是我的代码:

<asp:LoginStatus ID="LoginStatus1" OnLoggingOut="Logout_Click"  runat="server" /> 

和C#:

public void Logout_Click(object sender, EventArgs e)
    {

        Session.Abandon();
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();


    }

这段代码并未结束会话,甚至没有重定向到登录页面。

Web.config:

<authentication mode="Forms" >
      <forms loginUrl="url"   timeout="20" domain="domain">
      </forms>
    </authentication>

多谢你们!

根据MSDN ,您的OnLoggingOut方法应具有类型为LoginCancelEventArgs 1个参数。

您在Logout_Click方法中具有的代码应该可以,但是由于您的方法签名不正确,因此不会被调用。

(object sender, LoginCancelEventArgs e)

是OnLoggingOut方法的实际签名。 并且您不需要调用session.abandon。

在您的按钮单击事件上编写以下代码

protected void Page_Load(object sender, EventArgs e)
{
    HttpContext.Current.Session.Abandon();
    HttpContext.Current.Response.Cookies.Clear();
    FormsAuthentication.SignOut();

    Response.Redirect("~/LoginPage.aspx");

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM