2011-06-14 69 views
1

我期待創建一個非常簡單的註銷頁面,但落在第一個障礙。簡單'註銷'ASP.NET頁面

這裏是我當前登錄頁面是否有幫助: http://pastebin.com/2xJH1DnT

protected void Page_Load(object sender, EventArgs e) 
{ 
    RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + 
     HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]); 
} 

我試着最初使用FormsAuthentication.SignOut();註銷代碼隱藏,但一直得到錯誤:

CS0103: The name 'FormsAuthentication' does not exist in the current context

我如何能實現註銷功能?

+6

你得到的錯誤是什麼? – lancscoder 2011-06-14 14:49:18

+1

你會得到什麼錯誤。你可以發佈嗎? – 2011-06-14 14:49:43

+1

有什麼錯誤?簽名後,您是否讓用戶重定向到登錄頁面? – Xhalent 2011-06-14 14:50:45

回答

3

你得到了哪些錯誤?正確的方法應該是:

FormsAuthentication.SignOut() 
FormsAuthentication.RedirectToLoginPage() 

這適用於如果您使用窗體身份驗證當然。

+0

這些方法中只有一種方法可以在任何時候使用 - 不需要這兩種方法。 – 2011-06-14 14:51:55

+3

好的,那麼微軟在這裏是錯的:http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.signout.aspx – 2011-06-14 14:53:43

+0

Davide。這工作完美。它使我退出並重定向了我。我想我現在要添加這個,而不是指定的「註銷」腳本。 – michaelmcgurk 2011-06-14 15:00:21

1
Session.Abandon(); 

FormsAuthentication.SignOut(); 
Response.Redirect(FormsAuthentication.LoginUrl); 
+0

謝謝你。我仍然收到錯誤:「CS0103:名稱'FormsAuthentication'在當前上下文中不存在」 – michaelmcgurk 2011-06-14 14:57:53

+0

「,那麼您需要添加一個using。 – 2011-06-14 14:59:40