/// <summary> /// 获取机器唯一码 /// </summary> /// <param name="key">唯一码命名</param> /// <returns></returns> public string GetMachineKey(string key) { string hitkey = ManageCookies.GetCookieValue(key); if (string.IsNullOrEmpty(hitkey)) { hitkey = Guid.NewGuid().ToString(); ManageCookies.CreateCookie(key, hitkey, true, DateTime.Now.AddDays(1), CookieDomain, true); } return(hitkey); }
/// <summary> /// 用户登录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btSave_Click(object sender, EventArgs e) { if (Page.IsValid) { string userName = StrHelper.Trim(txtUserName.Value); string password = StrHelper.Trim(txtUserPwd.Value); ///用户名,密码,验证码不允许为空 if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { int id = Admins.Instance.ValiUser(userName, EncryptString.MD5(password));//验证用户 if (id > 0) { AdminInfo admin = Admins.Instance.GetAdmin(id); if (admin.State == "1") { admin.LastLoginIP = WebHelper.GetClientsIP(); admin.LastLoginTime = DateTime.Now; admin.LoginTimes++; Admins.Instance.UpdateAdmin(admin); LoginRecordInfo lr = new LoginRecordInfo() { AdminID = admin.ID, LastLoginIP = admin.LastLoginIP, LoginTime = DateTime.Now, UserName = admin.UserName }; Admins.Instance.AddLoginRecord(lr); Session[GlobalKey.SESSION_ADMIN] = admin; ManageCookies.CreateCookie(GlobalKey.SESSION_ADMIN, id.ToString(), true, DateTime.Today.AddDays(1), HXContext.Current.CookieDomain); Response.Redirect("index.aspx"); } else { lblMsg.Text = "用户状态异常,请联系管理员"; } } else { lblMsg.Text = "用户名或密码错误"; } Session[GlobalKey.SESSION_ADMIN] = null; } } }