Beispiel #1
0
        /// <summary>
        /// 登出
        /// </summary>
        /// <returns></returns>
        public ActionResult LogOff()
        {
            IFormsAuthentication _formAuthentication = new DefaultFormsAuthentication();

            //IFormsAuthentication _formAuthentication = DependencyResolver.Current.GetService<IFormsAuthentication>();
            _formAuthentication.Signout();
            return(RedirectToAction("Index", "Login"));
        }
Beispiel #2
0
        private void PostAuthenticateRequestHandler(object sender, EventArgs e)
        {
            HttpCookie authCookie = this.Context.Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authCookie != null && !string.IsNullOrEmpty(authCookie.Value))
            {
                //var formsAuthentication = DependencyResolver.Current.GetService<IFormsAuthentication>();
                IFormsAuthentication formsAuthentication = new DefaultFormsAuthentication();

                var ticket = formsAuthentication.Decrypt(authCookie.Value);
                try
                {
                    var mvcUser = new MVCUser(ticket);
                    this.Context.User = new GenericPrincipal(mvcUser, null);
                    formsAuthentication.SetAuthCookie(this.Context, ticket);
                }
                catch
                {
                    //清掉Session重登
                    formsAuthentication.Signout();
                    HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(string.Empty), null);
                }
            }
        }