2016-09-20 95 views
1

我在用戶登錄時隱藏的主頁面中有一個「註銷」按鈕。如何使用「FormsAuthentication」 - 方法登錄時隱藏「註銷」按鈕?

登錄功能非常簡單,由Web.config文件中的以下代碼實現(以及在一些簡單的代碼的登錄頁面):

<authentication mode="Forms"> 
    <forms name="KunstCookie" 
      loginUrl="InnUtlogging.aspx" 
      defaultUrl="SalgsOversiktAdmin.aspx" 
      protection="All" 
      timeout="30" path="/" /> 
    </authentication> 

我設法登錄和退出使用我成立了一個登錄頁面的用戶名和密碼。

我試圖隱藏註銷按鈕當我登錄通過在masterPage.master.cs文件下面的代碼:

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (Session["kunstCookie"] != null) 
    { 
     ButtonLogout.Visible = false; 
    } 
} 

但按鈕仍然存在,當我登錄英寸加載頁面時沒有錯誤消息。它幾乎就像cookie文件不存在或什麼的。

感謝任何幫助。

回答

0

找到了如何做到這一點。相反的:

if (Session["kunstCookie"] != null) 

我插入:

if (!HttpContext.Current.User.Identity.IsAuthenticated) 

我在這裏找到了答案:

Login and Logout in master page