zoukankan      html  css  js  c++  java
  • Cookie

    <body>
        <form id="form1" method="post" action="rembPage.aspx">
        <div>
            帐号: <input type="text" name="userName" /><br />
            密码 :<input type="password" name="pass" /><br />
            记住我: <input type="checkbox" value="rem" name="sele1" /><br />
            <input type="submit" value=" 登录 " /> 
        </div>
        </form>
    </body>

    protected void Page_Load(object sender, EventArgs e)
    {
    if (Request.Cookies["userName"] == null && Request.Cookies["passWord"] == null) //判断是否存在cookie,如果存在表示上次选择了记住我
    {
    if (Request.Form["userName"] != null && Request.Form["pass"] != null)
    {
    String userName = Request.Form["userName"];
    String userPassWord = Request.Form["pass"];
    if (userName == "admin" && userPassWord == "123")
    {
    if (Request.Form["sele1"] != null)
    {
    HttpCookie cookieUserName = new HttpCookie("userName", userName); //创建帐号的cookie实例
    HttpCookie cookiePassWord = new HttpCookie("passWord", userPassWord);
    cookieUserName.Expires = DateTime.Now.AddDays(2); //设置帐号cookie的过期时间,当前时间算往后推两天
    cookiePassWord.Expires = new DateTime(2012, 5, 27); //设置密码cookie的过期时间,过期时间为2012年5月27日
    Response.Cookies.Add(cookieUserName); //将创建的cookieUserName文件输入到浏览器端
    Response.Cookies.Add(cookiePassWord);
    Response.Redirect("1.aspx"); //跳转到你想要的页面
    }
    else
    {
    Response.Redirect("1.aspx");//即便不记住密码也要跳转
    }
    }

    }
    }
    else
    {
    Response.Redirect("1.aspx");//如果记住密码,第二次登录将直接进入1.aspx页面
    }
    }

    再三须慎意,第一莫欺心
  • 相关阅读:
    HDU1029 Ignatius and the Princess IV
    UVA11039 Building designing【排序】
    UVA11039 Building designing【排序】
    POJ3278 HDU2717 Catch That Cow
    POJ3278 HDU2717 Catch That Cow
    POJ1338 Ugly Numbers(解法二)
    POJ1338 Ugly Numbers(解法二)
    UVA532 Dungeon Master
    UVA532 Dungeon Master
    POJ1915 Knight Moves
  • 原文地址:https://www.cnblogs.com/otsf/p/8529450.html
Copyright © 2011-2022 走看看