Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET4.0
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 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
0 Sergey Alexandrovich Kryukov 717
1 ChauhanAjay 135
2 Maciej Los 130
3 ashok rathod 90
4 ChintanShukla 90
0 Sergey Alexandrovich Kryukov 10,200
1 OriginalGriff 6,987
2 CPallini 5,850
3 George Jonsson 4,015
4 Gihan Liyanage 3,266


Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 3 Jun 2013
Copyright © CodeProject, 1999-2014
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