日期:2014-05-17 浏览次数:20758 次
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HttpCookie myCookie = Request.Cookies["Login"];
if (myCookie != null && myCookie.Values["UserName"] != null && myCookie.Values["Password"] != null)
{
//取出Cookie中的值,显示到文本框中,
txtUserName.Text = Request.Cookies["Login"]["UserName"].ToString();
txtPassword.Text = Request.Cookies["Login"]["Password"].ToString();
}
}
}
//点击登陆按钮,保存Cookie中的值,跳转到另一个页面,另一个页面有个HyperLink,点击又跳转到登陆页面
protected void btnLogin_Click(object sender, EventArgs e)
{
if (txtUserName.Text == "admin" && txtPassword.Text == "123")
{
Response.Cookies["Login"]["UserName"] = txtUserName.Text.Trim();
Response.Cookies["Login"]["Password"] = txtPassword.Text.Trim();
Response.Cookies["Login"].Expires = DateTime.Now.AddDays(Convert.ToDouble(5));
Response.Redirect("Test.aspx");
}
}