/// <summary>
/// 判断Cookie中存储的数据
/// </summary>
protected void CheckUserCookie()
{
//先判断Cookie是否有值
if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null)
{
//校验数据是否正确.
string cookieUserName = Request.Cookies["cp1"].Value;
string cookieUserPwd=Request.Cookies["cp2"].Value;
BLL.UserManager bll = new BLL.UserManager();
Model.User model=bll.GetModel(cookieUserName);//根据Cookie中存储的用户名找用户
if (model != null)
{
//判断密码是否正确.
//如果注册时,采用相同的加密方式,那么这里再比较时直接比较
if (Enctry(model.LoginPwd) == cookieUserPwd)
{
Session["UserInfo"] = model;
GoPage("登录成功");
}
else//表示密码错误,删除Cookie
{
Response.Cookies["cp1"].Expires = DateTime.Now.AddDays(-);
Response.Cookies["cp2"].Expires = DateTime.Now.AddDays(-);
}
}
}
}
/// <summary>
/// 校验用户登录信息
/// </summary>
protected void CheckUserLogin()
{
string txtName=Request.Form["txtName"];
string txtPwd=Request.Form["txtPwd"];
BLL.UserManager bll = new BLL.UserManager();
string msg = string.Empty;
Model.User model = null;
//校验用户名密码
bool b= bll.UserLogin(txtName, txtPwd,out msg,out model);
if (b)
{
Session["UserInfo"] = model;
//如果选择了记住我复选框,将用户的信息写到Cookie。
if (!string.IsNullOrEmpty(Request.Form["checkMe"]))
{
HttpCookie cookie1 = new HttpCookie("cp1", model.LoginId);
HttpCookie cookie2 = new HttpCookie("cp2",Enctry(model.LoginPwd));
cookie1.Expires = DateTime.Now.AddDays();
cookie2.Expires = DateTime.Now.AddDays();
Response.Cookies.Add(cookie1);
Response.Cookies.Add(cookie2);
}
GoPage(msg); }
else
{
Response.Redirect("/ShowMsg.aspx?msg=" + Server.UrlEncode(msg) + "&txt=" + Server.UrlEncode("登录页") + "&url=/Login.aspx");
}
}

最新文章

  1. GO语言总结(4)——映射(Map)
  2. 前端打包/自动化构建工具:fis3
  3. 安装 phpredis 扩展
  4. phpstorm使用svn爆出“cannot load supported formats” 的解决
  5. [iOS]开发者证书和描述文件的作用
  6. 【从无到有】教你使用animation做简单的动画效果
  7. oracle数据库常用的99条查询语句(转载)
  8. .net随笔--不好归类的
  9. JAVA之旅(七)——final关键字 , 抽象类abstract,模板方法模式,接口interface,implements,特点,扩展
  10. 【带着canvas去流浪(8)】碰撞
  11. 人生苦短,我用Python(1)
  12. 征服诱人的Vagrant!
  13. MFC 键盘响应
  14. 工程师常犯的web后台界面用户体验错误
  15. Golang并发模型之Context详解
  16. SQLSERVER数据库调优
  17. array_rand
  18. 【redis专题(3)】命令语法介绍之link
  19. 修改eclipse.ini文件指定jdk
  20. C++ new和delete重载

热门文章

  1. html 标签 图片
  2. socket demo程序
  3. nagios 安装
  4. Linux虚拟机Centos 设置固定的静态IP
  5. Blue Jeans - poj 3080(后缀数组)
  6. makefile编写---单个子目录编译自动变量模板ok
  7. 有向图 加最少的边 成为强连通分量的证明 poj 1236 hdu 2767
  8. phpcms v9 配置sphinx全文索引教程
  9. Unity3D学习笔记——IDE工作视图
  10. 绝对定位position: absolute;