Esempio n. 1
0
 /// <summary>
 /// 判断管理员是否已经登录(解决Session超时问题)
 /// </summary>
 public bool IsAdminLogin()
 {
     //如果Session为Null
     if (Session["AdminNo"] != null && Session["AdminName"] != null && Session["AdminLevel"] != null && Session["AdminType"] != null)
     {
         return(true);
     }
     else
     {
         //检查Cookies
         string adminname = Utils.GetCookie("AdminName", "DtCms"); //解密用户名
         string adminpwd  = Utils.GetCookie("AdminPwd", "DtCms");
         if (adminname != "" && adminpwd != "")
         {
             adminname = DESEncrypt.Decrypt(adminname); //解密用户名
             DtCms.BLL.Administrator bll = new DtCms.BLL.Administrator();
             if (bll.chkAdminLogin(adminname, adminpwd))
             {
                 DtCms.Model.Administrator model = new DtCms.Model.Administrator();
                 model = bll.GetModel(adminname);
                 Session["AdminNo"]    = model.Id;
                 Session["AdminName"]  = model.UserName;
                 Session["AdminType"]  = model.UserType;
                 Session["AdminLevel"] = model.UserLevel;
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 2
0
        protected void loginsubmit_Click(object sender, ImageClickEventArgs e)
        {
            string UserName = txtUserName.Text.Trim();
            string UserPwd  = txtUserPwd.Text.Trim();

            if (UserName.Equals("") || UserPwd.Equals(""))
            {
                lbMsg.Text = "请输入您要登录用户名或密码";
            }
            else
            {
                if (Session["AdminLoginSun"] == null)
                {
                    Session["AdminLoginSun"] = 1;
                }
                else
                {
                    Session["AdminLoginSun"] = Convert.ToInt32(Session["AdminLoginSun"]) + 1;
                }
                //判断登录
                if (Session["AdminLoginSun"] != null && Convert.ToInt32(Session["AdminLoginSun"]) > 3)
                {
                    lbMsg.Text = "登录错误超过3次,请关闭浏览器重新登录。";
                }
                else if (bll.chkAdminLogin(UserName, DESEncrypt.Encrypt(UserPwd)))
                {
                    DtCms.Model.Administrator model = new DtCms.Model.Administrator();
                    model = bll.GetModel(UserName);
                    Session["AdminNo"]    = model.Id;
                    Session["AdminName"]  = model.UserName;
                    Session["AdminType"]  = model.UserType;
                    Session["AdminLevel"] = model.UserLevel;
                    //设置超时时间
                    Session.Timeout          = 45;
                    Session["AdminLoginSun"] = null;
                    //写入Cookies
                    Utils.WriteCookie("AdminName", "DtCms", DESEncrypt.Encrypt(model.UserName));
                    Utils.WriteCookie("AdminPwd", "DtCms", model.UserPwd);
                    //保存日志
                    new DtCms.Web.UI.ManagePage().SaveLogs(UserName, "[用户登录]状态:登录成功!");

                    Response.Redirect("admin_index.aspx");
                }
                else
                {
                    lbMsg.Text = "您输入的用户名或密码不正确";
                    //保存日志
                    new DtCms.Web.UI.ManagePage().SaveLogs(UserName, "[用户登录] 状态:登录失败!");
                }
            }
        }