[英]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.