首页 > 其他 > 详细

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

时间:2016-07-21 06:20:47      阅读:230      评论:0      收藏:0      [点我收藏+]
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";
    }
}

 

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

原文:http://www.cnblogs.com/suiyuejinghao123/p/5690234.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!