protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["myCookie"] != null)
{
HttpCookie cookie = Request.Cookies.Get("myCookie");
txtUserName.Text = cookie.Values["username"];
txtPassword.Attributes.Add("value", cookie.Values["password"]);
}
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
bool IsRemember = chkRememberMe.Checked;
if (IsRemember)
{
myCookie.Values.Add("username", txtUserName.Text);
myCookie.Values.Add("password", txtPassword.Text);
myCookie.Expires = DateTime.Now.AddDays(15);
}
else
{
myCookie.Values.Add("username", string.Empty);
myCookie.Values.Add("password", string.Empty);
myCookie.Expires = DateTime.Now.AddMinutes(5);
}
Response.Cookies.Add(myCookie);
}