2016-09-20 92 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