So I have a simple log-in form. This is what I have coded in in the code behind using C#:
string user = txtUserName.Text.Trim(); string pwd = txtPassword.Text; DataTable dt = new DataTable(); using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString)) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; // cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "SELECT username, password FROM member WHERE username='" + user + "' AND password='" + pwd + "' "; con.Open(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(dt); if (dt.Rows.Count > 0) { Session.Add("Username", dt.Rows[0][0].ToString()); Session.Add("Password", dt.Rows[0][1].ToString()); Response.Redirect("~/index.aspx", false); } else { lblErrorMessage.Text = "Invalid username or password"; }
This is what I put in my masterpage
<asp:LoginView ID="LoginView1" runat="Server">
<AnonymousTemplate>
<span style="font-family: Arial; font-size: 10pt;">Welcome, Guest!
[ <a href="~/Login.aspx" id="LoginStatus" runat="server">Log-In</a> ]
</span>
</AnonymousTemplate>
<LoggedInTemplate>
Welcome, <asp:Label ID="lblName" runat="server"></asp:Label>!
[ <a href="~/Login.aspx" id="LoginStatus" runat="server">Log-Out</a> ]
</LoggedInTemplate>
</asp:LoginView>
And this is what I have for the web.config
<configuration>
<connectionStrings>
<add name="DBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<authentication mode="Forms">
<forms name="myCookies" loginUrl="~/login.aspx" timeout="2880" />
</authentication>
</system.web>
</configuration>
Now the problem is I can't even display out the "log out" word and it doesn't even display out the name of the user also. My logged in works, but but the status is perpetually remain login and user(anonymous template). Any solution?