MVC 登录验证设置form验证
2012-06-15 18:42
204 查看
处理方法 [HttpPost] public ActionResult Index(Models.User model) { if (model.UserName == "admin") { //创造票据 FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(model.UserName, false, 1); //加密票据 string ticString = FormsAuthentication.Encrypt(ticket); //输出到客户端 Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, ticString)); //跳转到登录前页面 return Redirect(HttpUtility.UrlDecode( Request.QueryString["ReturnUrl"])); } return View(); }
退出.
通过 new FormsAuthenticationTicket(model.UserName, false, 时长); 设置.AXPXAUTH过期时长. 但是如果newHttpCookie(FormsAuthentication.FormsCookieName, ticString) 这个cookie对象没有设置过期时间, 那么上面设置的时长再长, cookie的生命周期还是浏览器的生命周期.
http://www.cnblogs.com/jianjialin/archive/2011/07/06/2099270.htmlpublic ActionResult Logout() { FormsAuthentication.SignOut(); return Redirect(FormsAuthentication.LoginUrl); }
相关文章推荐
- Ajax+SpringMVC+JSON登录验证
- JWT生成JsonWebToken登录令牌并使用自定义过滤器验证(包含跨域设置)
- Asp.Net Form验证不通过,重复登录
- mvc中的action验证登录(ActionFilterAttribute)
- hiveserver2 设置用户登录验证
- MicrosoftMvcJQueryValidation.js 启用客户端验证,form无法提交
- asp.net MVC 通用登录验证模块
- ASP.NET MVC Form验证
- 【MVC】会员注册/登录,普通验证,会员名是否注册Ajax验证以及会员邮件验证实现原理
- 设置Microsoft SQL Server Management Studio Express--使用SQL验证登录(如使用sa用户登录)
- 在web.config里面怎么设置FORMS验证:某几个页面可以匿名访问,其他页面都需要登录
- 通过基本设置和xp网络级别身份验证设置使xp可以远程登录win8系统
- ASP.NET_FORM表单验证_单点登录_Nomads (FormsAuthentication)
- ASP.NET MVC使用AuthenticationAttribute验证登录
- redis设置数据库密码及登录验证
- Java web实现登录验证和过滤器权限设置
- 【MVC】会员注册/登录,普通验证,会员名是否注册Ajax验证以及会员邮件验证实现原理
- django - 表单(form)验证及错误提示设置
- SpringMVC+Apache Shiro+JPA(hibernate)案例教学(二)基于SpringMVC+Shiro的用户登录权限验证
- spring mvc中设置登录拦截器,报错:元素 "mvc:interceptors" 的前缀 "mvc" 未绑定。