Click here to Skip to main content
12,505,389 members (72,831 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET4
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
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
 
good
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);

con1.Open();
SqlDataReader dr = cmd1.ExecuteReader();
if (dr.Read())
{
con1.Close();
Session["UserAuthentication"] = username;
Response.Redirect("main.aspx");
}


else
lblLoginFaild.Visible = true;

}


in mainPage.aspx

protected void Page_Load(object sender, EventArgs e)
{
if ( Session["UserAuthentication"] == mull)
{
Response.Redirect("~/login.aspx");
}
}
  Permalink  

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 | Mobile
Web02 | 2.8.160927.1 | Last Updated 3 Jun 2013
Copyright © CodeProject, 1999-2016
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