2011-01-19 160 views
-1

我是ASP.NET新手,遇到一些困難。我在下面有一個註冊和登錄,在一個頁面中。但是,當用戶登錄時,我希望隱藏註冊和登錄表單。 用戶登錄時有一個LOGOUT選項。 任何指導都會很棒,謝謝!當用戶登錄時隱藏註冊和登錄表單ASP.NET

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %> 

<script runat="server"> 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 

    End Sub 

    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) 

    End Sub 

    Protected Sub Login1_Authenticate1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) 

    End Sub 

    Protected Sub Login1_Authenticate2(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) 

    End Sub 



Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) 

End Sub 
</script> 

<%-- Add content controls here --%> 
<asp:Content ID="Content1" runat="server" 
    contentplaceholderid="ContentPlaceHolder1"> 
    <table width="640px"><tr> 
    <td width="360px"> 
        <p> 
         <asp:CreateUserWizard ID="CreateUserWizard1" runat="server"> 
          <WizardSteps> 
           <asp:CreateUserWizardStep runat="server" /> 
           <asp:CompleteWizardStep runat="server" /> 
          </WizardSteps> 
         </asp:CreateUserWizard> 
</p> 
        <br /> 
        <br /> 
        </td> 
        <td width="270px"> 
         <p> 
     <asp:Login ID="Login1" runat="server" DestinationPageUrl="~/Home.aspx"> 
     </asp:Login> 
     <asp:LoginView ID="LoginView1" runat="server"> 
      <AnonymousTemplate> 
       Please log In 
      </AnonymousTemplate> 
     </asp:LoginView> 
</p> 
    <p> 
     <asp:LoginStatus ID="LoginStatus1" runat="server" /> 
</p> 
</td> 
</tr> 
</table> 


</asp:Content> 

回答

0

您可以使用User.Identity.IsAuthenticated弄清楚,如果他們驗證過了。如果是,則可以將控件的可見性設置爲false。

在你的Page_Load方法,把一些看起來像這樣:

if (User.Identity.IsAuthenticated) 
      CreateUserWizard1.Visible = Login1.Visible = False 
+0

您好,感謝您的答覆。不過,我已經通過示例 - 教程建立了迄今爲止,我找不到任何熟悉的。請,如果你有幾分鐘給我一個例子。謝謝! – endero 2011-01-19 05:57:33

+0

嘿,謝謝!請讓我知道如何修改此用戶未登錄如果(User.Identity.IsAuthenticated) – endero 2011-01-19 06:26:14

0

我建議LoginView。

<asp:LoginView ID="LoginView1" runat="server"> 
     <LoggedInTemplate> 
      <asp:LoginStatus ID="LoginStatus1" runat="server" /> 
      <asp:LoginName ID="LoginName1" runat="server" /> 
     </LoggedInTemplate> 
     <AnonymousTemplate> 
      <p> 
       <asp:Login ID="Login1" runat="server"> 
       </asp:Login> 
      </p> 
      <p> 
      <asp:CreateUserWizard ID="CreateUserWizard1" runat="server"> 
       <WizardSteps> 
        <asp:CreateUserWizardStep runat="server" /> 
        <asp:CompleteWizardStep runat="server" /> 
       </WizardSteps> 
      </asp:CreateUserWizard> 
      </p> 
     </AnonymousTemplate> 
</asp:LoginView> 
0
<asp:Login VisibleWhenLoggedIn="True|False" /> 

    Gets or sets a value indicating whether to show the Login control after the user is authenticated. 

    For Example: 
    <%@ Page Language="VB" AutoEventWireup="False"%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head> 
     <title>Login Sample</title> 
    </head> 
    <body> 
     <form id="form1" runat="server"> 
      <asp:Login id="Login1" runat="server" 
       VisibleWhenLoggedIn="false"> 
      </asp:Login> 
    </form> 
    </body> 
    </html>