Click here to Skip to main content
13,199,026 members (42,858 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Please give me code for understanding how to start session when a user login successfully.Please help friends.
Posted 10-Nov-12 9:35am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Assuming if the user name and password stored in database , ex : stored in login table
in login page:

protected void butnLogin_Click(object sender, EventArgs e)
SqlConnection con1 = new SqlConnection();
con1.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
string sql1 = " select * from Login where Email = @email and Pass = @pass";
SqlCommand cmd1 = new SqlCommand(sql1, con1);
cmd1.Parameters.AddWithValue("email", txtEmail.Text);
cmd1.Parameters.AddWithValue("pass", txtPass.Text);

SqlDataReader dr = cmd1.ExecuteReader();
if (dr.Read())
Session["UserAuthentication"] = username;

lblLoginFaild.Visible = true;


in mainPage.aspx

protected void Page_Load(object sender, EventArgs e)
if ( Session["UserAuthentication"] == mull)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171020.1 | Last Updated 3 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100