最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 使用cookie完成记住密码自动登录
时间:2011-11-19 编辑:简简单单 来源:一聚教程网
//------------------------------登录页面----------------------------
代码如下 | 复制代码 |
if (UserManager.LoginValidate(username, password) && this.ckState.Checked == true)//判断登录名和密码是否正确和是否选择了记住用户名和密码的复选框 if (Request.Cookies["username"] != null && Request.Cookies["password"] != null) |
//------------------------转到登录后的页面(有母板页写母板页最好)------------------------
代码如下 | 复制代码 |
if (Request.Cookies["username"] != null && Request.Cookies["password"] != null) { //用户曾登录 username = Request.Cookies["username"].Value.ToString(); //读取Cookie password = Request.Cookies["password"].Value.ToString();//判断Cookie读取出来的用户名和密码是否能正确登录 if (UserManager.LoginValidate(username, password)) { //登录后的代码 } } |
//-------------------------------Cookie退出(加一个退出按钮)-------------------------------
//退出
代码如下 | 复制代码 |
HttpCookie hcUserName1 = new HttpCookie("username"); hcUserName1.Expires = System.DateTime.Now.AddDays(-7); hcUserName1.Value = username; HttpCookie hcPassword1 = new HttpCookie("password"); hcPassword1.Expires = System.DateTime.Now.AddDays(-7); hcPassword1.Value = password; Response.Cookies.Add(hcUserName1); Response.Cookies.Add(hcPassword1); |
-
下一个: asp.net防sql注入代码
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10