Exemplo n.º 1
0
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                if (User.Identity.IsAuthenticated)
                {
                    var id = User.Identity as FormsIdentity;
                    if (id != null)
                    {
                        if (!CurrentUser.IsAuthenticated)
                        {
                            CurrentUser = AuthenticationProvider.GetUser(User.Identity.Name);
                            CurrentUser.IsAuthenticated = true;

                            //CurrentUser.Data.Add(new KeyValuePair<string, object>(User.));
                        }
                    }
                }
            }
            else
            {
                if (String.Compare(filterContext.RouteData.Values["controller"].ToString(), "Account", StringComparison.InvariantCultureIgnoreCase) != 0)
                {
                    filterContext.Result = new RedirectToRouteResult(new
                                                                     RouteValueDictionary(new { controller = "Account", action = "Login" }));
                }
            }
            Thread.CurrentPrincipal = CurrentUser;
            HttpContext.User        = CurrentUser;
        }