zoukankan      html  css  js  c++  java
  • 简单的Cookie登录

    登录页前台代码

        <form id="form1" action ="" method="post">
            <input type="text" name="txtN" />
            <input type="password" name="txtP" />
            <input type="submit" value="登陆" />
        </form>
    

     登录页面后台代码

      protected void Page_Load(object sender, EventArgs e)
            {
                if (Request.HttpMethod.ToLower() == "post")
                {
                    string strN = Request.Form["txtN"];
                    string strP = Request.Form["txtP"];
                    //登录成功
                    if (strN == "admin" && strP == "123")
                    {
                        //创建Cookie  存入  键值对
                        HttpCookie cookie = new HttpCookie("cname", strN);
                        //设置失效时间(硬盘Cookie)
                        cookie.Expires = DateTime.Now.AddMinutes(2);//2分钟内免登陆
                        //加入响应报文对象
                        Response.Cookies.Add(cookie);

                        //让浏览器重定向到首页
                        Response.Redirect("cookieIndex.aspx");
                    }
                }
            }

     首页后台代码

     protected void Page_Load(object sender, EventArgs e)
            {
                //获取浏览器端发来的Cookie
                HttpCookie cookie = Request.Cookies["cname"];
                //如果没有则跳转到登录页面
                if (cookie == null)
                {
                    Response.Write("<script>alert('您还没有登录~~!');window.location='CookieLogin.aspx';</script>");
                    Response.End();
                }
                else
                {
              //如果有则把Cookie里保存的用户名显示出来 Response.Write("欢迎你登录"+cookie.Value); } }

    图解:

    ok结束

  • 相关阅读:
    react15
    react14
    react13
    react12
    react11
    【医学图像处理】提取勾画
    【图像分割 损失函数】Loss functions for image segmentation
    【批处理】子文件夹压缩包和指定后缀名文件
    【版本更新】PerfDog 5.0强势来袭,业界首创支持GPU详细信息采集与众多升级优化
    感知行业风向,掌握质量脉动,腾讯WeTest发布《2020移动游戏质量白皮书》
  • 原文地址:https://www.cnblogs.com/mekor/p/3670590.html
Copyright © 2011-2022 走看看