Asp.Net Form验证
2015-11-12 17:54
645 查看
1、web.config 必需定义
hrmstaffID为auth Cookie的名称;webapp为必须认证后才能访问的目录
2、登录成功时,写入Cookie
3、退出登录,消除Cookie
<pre name="code" class="html"><configuration> <system.web> <authentication mode="Forms"> <forms name="hrmstaffID" loginUrl="/index.html" timeout="1440"/> </authentication> </system.web> <location path="webapp"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location> </configuration>
hrmstaffID为auth Cookie的名称;webapp为必须认证后才能访问的目录
2、登录成功时,写入Cookie
<span style="white-space:pre"> </span>DateTime timeExpires; if (ischeck == "1") { timeExpires = DateTime.Now.AddDays(30); } else { timeExpires = DateTime.Now.AddHours(12); } FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 2, FormsAuthentication.FormsCookieName, DateTime.Now, timeExpires, true, PSMDL.id.ToString()); string cookieValue = FormsAuthentication.Encrypt(ticket); HttpCookie myCookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieValue); myCookie.Expires = timeExpires; HttpContext.Current.Response.Cookies.Add(myCookie);
3、退出登录,消除Cookie
FormsAuthentication.SignOut();
相关文章推荐
- asp.net中操作Word问题记录
- asp.net mvc 发送邮箱验证码
- asp.net请求管道和页面生命周期
- asp.net日期格式出现"/"的问题
- iOS设置按钮的图片为Aspetfit
- asp.net发布webservice出现‘Could not write to output file ‘解决办法
- asp.net微信开发(开发者接入)
- ASP.NET MVC 网站优化总结 使用 Gzip 压缩
- 实现在ASP中对字符的Escape编码和解码
- 智能家居喂鱼系统(二)-器材介绍
- URLRewrite伪静态后AspNetPager分页控件列表输出的静态化方法
- ASP.NET 弹出提示框所有种类
- ASP.NET中的DataView用法详解
- ASP.NET MVC 4 中的JSON数据交互
- NoClassDefFoundError: org/aspectj/lang/JoinPoint
- ASP.NET MVC- 使用PageList.Mvc分页
- Asp.net MVC中传递ViewData数据不能正确传递的问题
- asp.net微信开发(开发者接入)
- ASP.NET MVC - Display UTC time from server as local time on client side
- WPF/ASP.NET:几个Prism中的术语