COOKIES 的使用,事件控制的应用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default11 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Click += Button1_Click;
    }

    void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "zhangsan" && TextBox2.Text == "123")
        {
            //1、记住当前用户的登陆状态
            Response.Cookies.Add(new HttpCookie("UserName", TextBox1.Text));

            Response.Cookies["Pwd"].Value = TextBox2.Text;

            //2、是否需要长时间保存
            if (CheckBox1.Checked)
            {
                Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(7);
                Response.Cookies["Pwd"].Expires = DateTime.Now.AddDays(7);
            }
            Response.Redirect("Default12.aspx");
        }
        else
        { 
        
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default11 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Click += Button1_Click;
    }

    void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "zhangsan" && TextBox2.Text == "123")
        {
            //1、记住当前用户的登陆状态
            Response.Cookies.Add(new HttpCookie("UserName", TextBox1.Text));

            Response.Cookies["Pwd"].Value = TextBox2.Text;

            //2、是否需要长时间保存
            if (CheckBox1.Checked)
            {
                Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(7);
                Response.Cookies["Pwd"].Expires = DateTime.Now.AddDays(7);
            }
            Response.Redirect("Default12.aspx");
        }
        else
        { 
        
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default13 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Application["aaa"] = "V1.0";
    }
}

 

posted @ 2016-07-21 01:16  一人饮酒醉(SeVen❤)  阅读(228)  评论(0编辑  收藏  举报