session state with user login

N

nasirmajor

dear all,
a simple quetion from still a beginner in asp.net
i have a simple webpage with username and password which is linked with
database. now when user gives
his username and password and if information is right he does move to
the required webpage. but i want
the session to start with his successful login. how to store his id in
session and start and end it when
logout is clicked.
please any small code sample that can help me.or any good relevent
article to this quetion.
thankyou in advance
nasir
 
N

nasirmajor

my aspx file code is as follows:-


<script runat="server">
SqlConnection objconn=new SqlConnection("user
id=sa;password=;Initial Catalog=jobsdb;Data Source=localhost;Integrated
Security=SSPI;");

SqlDataReader objDR;

bool CheckCredentials(string identity2, string Password)
{
objconn.Open();
SqlCommand objcmd=new SqlCommand("SELECT username2,password2
from tbl_login where username2=@username2",objconn);
objcmd.Parameters.Add(new SqlParameter("@username2",
SqlDbType.VarChar, 50));
objcmd.Parameters["@username2"].Value = TextBox1.Text;

objDR = objcmd.ExecuteReader();


if (!objDR.Read())
{
return false;
}
else
{
string strstoredpassword=(string)objDR["password2"];
string strgivenpassword=TextBox2.Text;

return strstoredpassword==strgivenpassword;

}

}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckCredentials(TextBox1.Text, TextBox2.Text) == true)
{
string url = "cpanelhome.aspx";
Response.Redirect(url);

}
else
{
Label1.Text = "You entered the wrong credentials!";
}


}
</script>

textbox1 is for username
textbox2 is for password

which works correctly. i want session addition in this code.
thankyou again in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top