MVC 登录验证设置form验证

处理方法
[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的生命周期还是浏览器的生命周期.
public ActionResult Logout() {
            FormsAuthentication.SignOut();
            return Redirect(FormsAuthentication.LoginUrl);
        }

http://www.cnblogs.com/jianjialin/archive/2011/07/06/2099270.html

作者:dupeng0811
版权:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接
留言:同时 , 如果文中有什么错误,欢迎指出。以免更多的人被误导。
原文地址:https://www.cnblogs.com/dupeng0811/p/2551078.html