When I set the VisibleWhenLoggedIn property of my Login control to false, my Login control automatically becomes invisible even if I'm not logged in. I've already set the Authenticate event to use my own SQL database, but this problem is still persisting. How do I fix this?
Here is the code:
<asp:Login ID="frmLogin" runat="server" onauthenticate="frmLogin_Authenticate" VisibleWhenLoggedIn="False"></asp:Login>
protected void frmLogin_Authenticate(object sender, AuthenticateEventArgs e)
{
string email = frmLogin.UserName;
string pw = frmLogin.Password;
string connection = "Data Source=[Removed for privacy purposes];
SqlConnection conn = new SqlConnection(connection);
conn.Open();
string command = "SELECT [EmailAddress], [Password] FROM Members WHERE (EmailAddress = '" + email + "' AND Password = '" + pw + "')";
SqlCommand cmd = new SqlCommand(command, conn);
cmd.ExecuteNonQuery();
SqlDataReader myReader = cmd.ExecuteReader();
bool hasContent = myReader.Read();
if (hasContent == true)
{
e.Authenticated = true;
Response.Redirect("/Default.aspx");
}
else
{
e.Authenticated = false;
frmLogin.FailureText = "Incorrect email/password combination.";
}
}