/// <summary> /// 从Cookie中读取认证信息 /// </summary> /// <returns></returns> public static ISignInInfo LoadFromCookie() { SignInInfo signInInfo = null; Common.CheckHttpContext(); HttpRequest request = HttpContext.Current.Request; HttpCookie cookie = request.Cookies[GetLoadingCookieKey()]; if (cookie != null) { string strSignIn = cookie.Value; try { signInInfo = new SignInInfo(Common.DecryptString(strSignIn)); } catch (System.Exception) { //如果cookie的格式错误,不予理睬 } } return signInInfo; }
/// <summary> /// 从Cookie中读取认证信息 /// </summary> /// <returns></returns> public static ISignInInfo LoadFromCookie() { SignInInfo signInInfo = null; Common.CheckHttpContext(); HttpRequest request = HttpContext.Current.Request; HttpCookie cookie = request.Cookies[GetLoadingCookieKey()]; if (cookie != null) { string strSignIn = cookie.Value; try { signInInfo = new SignInInfo(Common.DecryptString(strSignIn)); } catch (System.Exception) { //如果cookie的格式错误,不予理睬 } } return(signInInfo); }
/// <summary> /// 清除认证服务的Cookie /// </summary> public static void ClearSignInCookie() { Common.CheckHttpContext(); HttpContext context = HttpContext.Current; HttpRequest request = context.Request; HttpResponse response = context.Response; HttpCookie cookie = request.Cookies[SignInInfo.GetLoadingCookieKey()]; if (cookie != null) { cookie.Expires = SNTPClient.AdjustedTime.AddDays(-1); cookie.Value = null; response.SetCookie(cookie); } }