using System; using System.Collections.Generic; using System.Configuration; using System.Data.SqlClient; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Newdelhibarassocia.dhadmin { public partial class Default : System.Web.UI.Page { SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); SqlDataAdapter adp; SqlCommand cmd; //Class1 obj = new Class1(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { yourUsername.Focus(); } } protected void btnLogin_Click(object sender, EventArgs e) { string sel = "select * from tb_usermaster where uid='" + yourUsername.Value + "' and password='" + yourPassword.Value + "'"; SqlDataAdapter da = new SqlDataAdapter(sel, connect); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { HttpCookie nameCookie = new HttpCookie("Siteid"); nameCookie.Secure = true; nameCookie.HttpOnly = true; //Set the Cookie value. nameCookie.Values["Siteid"] = dt.Rows[0]["smenu"].ToString(); //Set the Expiry date. nameCookie.Expires = DateTime.Now.AddDays(3); //Add the Cookie to Browser. Response.Cookies.Add(nameCookie); //Session["UserName"] = yourUsername.Value; // Session["menuname"] = dt.Rows[0]["smenu"].ToString(); Response.Redirect("HomePage.aspx"); } else { RegisterStartupScript("12", ""); } } } }