Page

Start Session And End Session In ASP.Net With help of SQL

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;

}


// mainPage.aspx



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

No comments:

Post a Comment