My Login Page Controls code is:
<table class="auto-style9">
<tr>
<td class="auto-style12" colspan="2" style="font-family:
Georgia; font-size: medium; font-weight: bold;
text-transform: uppercase; color: #000000">Login
</td>
</tr>
<tr>
<td class="auto-style15">User name</td>
<td class="auto-style15">
<asp:TextBox ID="UserNameTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Password </td>
<td class="auto-style15">
<asp:TextBox ID="PasswordTextBox" runat="server" TextMode="Password">
</asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15"> </td>
<td class="auto-style15">
<asp:Button ID="ButtonLogin" runat="server"
CommandName="Login" Text="Login!"
OnClick="ButtonLogin_Click" BackColor="Black"
ForeColor="Yellow" />
</td>
</tr>
</table>
My Button Login Click event is :
protected void ButtonLogin_Click(object sender, EventArgs e)
{
using(BerouDataContext Data = new BerouDataContext())
{
var UsernameCheck = UserNameTextBox.Text;
var PasswordCheck = PasswordTextBox.Text;
var UserExist = Data.Memberships.Single(s => s.Username == UsernameCheck);
if (UserExist == null || UserExist.Password != PasswordCheck)
{
LabelLoginValidity.Text = "Login Details are incorrect.";
}
else
{
LabelLoginValidity.Text = "Login Successfull!";
}
}
}
My Question is how to make cookie, how to code for loginStatus in c#, please Help with some code to implement, Thank You.
so basically, you want to determine, whether the user is logged- in or not.
you can make use of
Sessionvariable or aCookieVariableinside your
ButtonLogin_Clickin the else portion, when you successful login, add these linesNow this Session or Cookie variable, you can check on inner pages. something like inside your Home page
and you must destroy the Session or Cookie variable upon logout button click i.e.
So basically,
SessionandCookieare State Management techniques.Read more about them here