zoukankan      html  css  js  c++  java
  • 实现记住用户登陆名

    .aspx文件中

    <asp:TextBox ID="txtUser_Id" runat="server" MaxLength="4" Width="120px" BorderColor="LightSlateGray" BorderWidth="1px"></asp:TextBox><asp:ImageButton ID="btnInsert" runat="server" ImageUrl="~/Images/Login.GIF" OnClick="btnInsert_Click" /><asp:CheckBox ID="cbxRemeberUser" runat="server" Text="记住用户名" Font-Size="Small" ForeColor="gray"/>

    .aspx.cs文件中

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.txtUser_Id.Focus();
                if (!Object.Equals(Request.Cookies["UserID"], null))
                {
                    //创建一个Cookie对象,实现记住用户名
                    HttpCookie readcookie = Request.Cookies["UserID"];
                    this.txtUser_Id.Text = readcookie.Value;
                }
            }
        }
        private void CreateCookie()
        {
            //创建一个Cookie对象
            HttpCookie cookie = new HttpCookie("UserID");
            //判断Checkbox控件是否被选中
            if (this.cbxRemeberUser.Checked)
            {
                //将用户编号存储到创建的Cookie对象中
                cookie.Value = this.txtUser_Id.Text;
            }
            //获取创建的Cookie对象的过期时间
            cookie.Expires = DateTime.MaxValue;
            //将创建的Cookie对象添加到内部Cookie集合中
            Response.AppendCookie(cookie);
    }
    
        protected void btnInsert_Click(object sender, ImageClickEventArgs e)
        {
    …
            if (object.Equals(Request.Cookies["UserID"], null))
            {
              //调用自定义方法 CreateCookie()存储用户名
              CreateCookie();
            }
            else
            {
               CreateCookie();
            }
    …
    }
  • 相关阅读:
    python中使用cookies免登陆
    python中列表与元组的区别与转换
    python模块之mock
    python模块之Faker
    python模块之requests
    adb简单命令使用
    Mac下安装appium+python+Android sdk 环境完整流程
    git+pycharm结合使用
    github内的一些操作
    mac下git连接远程仓库gitee
  • 原文地址:https://www.cnblogs.com/52net/p/2523825.html
Copyright © 2011-2022 走看看