Asp.net Login Status Question: It Aint Working
- by contactmatt
I'm starting to use Role Management in my website, and I'm current following along on the tutorial from http://www.asp.net/Learn/Security/tutorial-02-vb.aspx .
I'm having a problem with the asp:LoginStatus control. It is not telling me that I am currently logged in after a successful login. This can't be true because after successfully logging in, my LoggedInTemplate is shown. The username and passwords are simply stored in a array. Heres the Login.aspx page code.
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles btnLogin.Click
' Three valid username/password pairs: Scott/password, Jisun/password, and Sam/password.
Dim users() As String = {"Scott", "Jisun", "Sam"}
Dim passwords() As String = {"password", "password", "password"}
For i As Integer = 0 To users.Length - 1
Dim validUsername As Boolean = (String.Compare(txtUserName.Text, users(i), True) = 0)
Dim validPassword As Boolean = (String.Compare(txtPassword.Text, passwords(i), False) = 0)
If validUsername AndAlso validPassword Then
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, chkRemember.Checked)
End If
Next
' If we reach here, the user's credentials were invalid
lblInvalid.Visible = True
End Sub
Here is the content place holder on the master page specifically designed to hold Login Information. On successfull login, the page is redirected to '/Default.aspx', and the LoggedIn Template below is shown...but the status says Log In.
<asp:ContentPlaceHolder Id="LoginContent" runat="server">
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
Welcome back, <asp:LoginName ID="LoginName1" runat="server" />.
</LoggedInTemplate>
<AnonymousTemplate>
Hello, stranger.
</AnonymousTemplate>
</asp:LoginView>
<br />
<asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutPageUrl="~/Logout.aspx" />
</asp:ContentPlaceHolder>
Forms authentication is enabled. I'm not sure what to do about this :o.