/// <summary>注销</summary> public ActionResult SignOut() { string accountIdentityName = KernelContext.Current.AuthenticationManagement.IdentityName; // 获取当前用户信息 IAccountInfo account = KernelContext.Current.User; KernelContext.Current.AuthenticationManagement.Logout(); // ------------------------------------------------------- // Session // ------------------------------------------------------- Session.Abandon(); HttpAuthenticationCookieSetter.ClearUserCookies(); Response.Cookies[accountIdentityName].Value = null; Response.Cookies[accountIdentityName].Expires = DateTime.Now.AddDays(-1); // ------------------------------------------------------- // IIdentity // ------------------------------------------------------- if (this.User != null && this.User.Identity.IsAuthenticated) { FormsAuthentication.SignOut(); } // 记录帐号操作日志 MembershipManagement.Instance.AccountLogService.Log(account.Id, "退出", string.Format("【{0}】在 {1} 登录了系统。【IP:{2}】", account.Name, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), IPQueryContext.GetClientIP())); return(View("/views/" + LocateFolder("main") + "/account/sign-out.cshtml")); }
// ------------------------------------------------------- // 退出帐号 // ------------------------------------------------------- #region 函数:Quit(XmlDocument doc) /// <summary>退出</summary> public string Quit(XmlDocument doc) { string identityName = KernelContext.Current.AuthenticationManagement.IdentityName; // 获取当前用户信息 IAccountInfo account = KernelContext.Current.User; KernelContext.Current.AuthenticationManagement.Logout(); // ------------------------------------------------------- // Session // ------------------------------------------------------- HttpContext.Current.Session.Clear(); // Mono 2.10.9 版本的 InProc 模式下调用 Session.Abandon() 会引发如下错误 // System.NullReferenceException: Object reference not set to an instance of an object at // System.Web.SessionState.SessionInProcHandler.GetItemInternal (System.Web.HttpContext context, System.String id, System.Boolean& locked, System.TimeSpan& lockAge, System.Object& lockId, System.Web.SessionState.SessionStateActions& actions, Boolean exclusive) if (Environment.OSVersion.Platform == PlatformID.Win32NT) { HttpContext.Current.Session.Abandon(); } HttpAuthenticationCookieSetter.ClearUserCookies(); HttpContext.Current.Response.Cookies[identityName].Value = null; HttpContext.Current.Response.Cookies[identityName].Expires = DateTime.Now.AddDays(-1); // ------------------------------------------------------- // IIdentity // ------------------------------------------------------- if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated) { FormsAuthentication.SignOut(); } // 记录帐号操作日志 MembershipManagement.Instance.AccountLogService.Log(account.Id, "membership.member.quit", string.Format("【{0}】在 {1} 退出了系统。【IP:{2}】", account.Name, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), IPQueryContext.GetClientIP())); return("{\"message\":{\"returnCode\":0,\"value\":\"已成功退出。\"}}"); }