Example #1
0
 protected override void OnAuthorization(AuthorizationContext filterContext)
 {
     FillAgent();
     if (filterContext.RouteData.DataTokens["area"] != null && filterContext.RouteData.DataTokens["area"].Equals("manage"))
     {
         SetCurrentCookies = filterContext.RequestContext.HttpContext.Request.Cookies;
         string cookieStr = GetCookieStr();
         if (string.IsNullOrEmpty(cookieStr))
         {
             string tmpRouteName  = RouteData.GetRequiredString("controller");
             string tmpActionName = RouteData.GetRequiredString("action");
             if (!tmpRouteName.Equals("account", StringComparison.InvariantCultureIgnoreCase) || (tmpRouteName.Equals("account", StringComparison.InvariantCultureIgnoreCase) && string.Equals(tmpActionName, "index", StringComparison.InvariantCultureIgnoreCase)))
             {
                 //filterContext.Result = new RedirectResult("/Account/Login");
                 filterContext.Result = new EmptyResult();
                 filterContext.HttpContext.Response.Write("<script>top.location ='/manage/account/login';</script>");
                 filterContext.HttpContext.Response.End();
             }
         }
         else if (string.IsNullOrEmpty(CookiesEvent.GetCookies(SetCurrentCookies, "accountInfo")))
         {
             RemoveStoredData();
             filterContext.Result = new EmptyResult();
             filterContext.HttpContext.Response.Write("<script>top.location ='/manage/account/login';</script>");
             filterContext.HttpContext.Response.End();
         }
     }
 }
Example #2
0
        /// <summary>
        /// 取得用户信息
        /// </summary>
        /// <returns></returns>
        public Account GetAccount()
        {
            string cookieStr = CookiesEvent.GetCookies(SetCurrentCookies, "accountInfo");

            if (!string.IsNullOrEmpty(cookieStr))
            {
                Account account = JsonConvert.DeserializeObject <Account>(GetBase64Generate(cookieStr));
                account.UserName = System.Web.HttpUtility.UrlDecode(account.UserName);
                return(account);
            }

            return(null);
        }
Example #3
0
 /// <summary>
 /// 返回认证cookie字符串
 /// </summary>
 /// <returns></returns>
 private string GetCookieStr()
 {
     return(CookiesEvent.GetCookies(SetCurrentCookies, "accountInfo"));
 }