复制代码 代码如下:
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HttpCookie cookie = Request.Cookies["loginInfo"];

            if (cookie != null)
            {
                cb_repwd.Checked = true;
                tb_loginName.Text = UIHelper.Decrypt(cookie["loginName"]);
                tb_pwd.Attributes.Add("value", UIHelper.Decrypt(cookie["pwd"]));
            }
            else
            {
                tb_pwd.Attributes.Add("value", "******");
            }

        }

    }

    protected void btn_login_Click(object sender, EventArgs e)
    {

        if (UIHelper.GetString(Session["Code"]).ToUpper()!=this.tb_code.Text.Trim().ToUpper())
        {
            oJavaScript.Alert("验证码输入不正确");
            return;
        }

        NetUserService NerService = ContextFactory.GetObject<NetUserService>("NetUserService");
        string sql = string.Format("from NetUser where LoginName='{0}'", tb_loginName.Text.Trim());
        IList<NetUser> list = NerService.Find(sql);
        if (list.Count > 0)
        {
            if (list[0].Status == 2)
            {
                oJavaScript.Alert("帐号已停用,请联系管理员");
                return;
            }
        }

        if (NerService.Login(tb_loginName.Text.Trim(), oSecurity.GetPwdEncrypt(tb_pwd.Text.Trim())))
        {
            HttpCookie cookie = Request.Cookies["loginInfo"];
            if (cb_repwd.Checked)
            {
                if (cookie == null)
                {
                    HttpCookie cookielogin = new HttpCookie("loginInfo");
                    setCookies(cookielogin,7);
                }
                else
                {
                    if (UIHelper.Decrypt(Request.Cookies["loginInfo"]["loginName"]) != tb_loginName.Text.Trim())
                    {
                        setCookies(cookie, 7);
                    }
                }
            }
            else
            {
                setCookieExpires(cookie);
            }

           
            oJavaScript.Redirect("/");
        }
        else
        {
            oJavaScript.Alert( "用户名或密码不正确");
        }
    }

    #region cookie
    /// <summary>
    /// 设置cookie
    /// </summary>
    /// <param name="cookielogin">HttpCookie cookielogin</param>
    /// <param name="Expires">有效期</param>
    private void setCookies(HttpCookie cookielogin, int Expires)
    {
        cookielogin.Values["loginName"] = UIHelper.Encrypt(tb_loginName.Text.Trim());
        cookielogin.Values["pwd"] = UIHelper.Encrypt(tb_pwd.Text.Trim());
        cookielogin.Expires = DateTime.Now.AddDays(Expires);
        Response.AppendCookie(cookielogin);
    }

    /// <summary>
    /// 设置cookie失效
    /// </summary>
    /// <param name="cookielogin">HttpCookie cookielogin</param>
    private void setCookieExpires(HttpCookie cookielogin)
    {
        if (cookielogin != null)
        {
            cookielogin.Expires = DateTime.Now.AddDays(-1); ;
            Response.AppendCookie(cookielogin);
        }
    }
    #endregion

设置cookie过期其实就是修改cookie,必须重新向客户端发送cookie

Request.Cookies取cookie, response,cookies添加cookie

虽然简单,但是不太了解的还是很容易出错

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。