Ejemplo n.º 1
0
        /// <summary>
        /// Initialize the controller by setting up UserState and ErrorDisplay
        /// </summary>
        protected virtual void Initialize(ActionExecutingContext context)
        {
            ViewBag.ErrorDisplay = ErrorDisplay;

            if (User != null && User.Identity != null && User.Identity.IsAuthenticated)
            {
                UserState = UserState.CreateFromUserClaims <TUserState>(HttpContext) as TUserState;
            }
            if (UserState == null)
            {
                UserState = new UserState();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method Parses user state from the User.Identity if the
        /// user is Authenticated. Otherwise the UserState object is
        /// left as an empty object.
        /// </summary>
        /// <param name="context"></param>
        protected virtual void ParseUserState(ActionExecutingContext context)
        {
            var controller = context.Controller as BaseApiController;

            if (controller == null)
            {
                return;  // can't parse return without userstate
            }
            var user          = context.HttpContext.User;
            var userStateType = controller.UserState.GetType();

            if (user != null && user.Identity != null && user.Identity.IsAuthenticated)
            {
                controller.UserState = UserState.CreateFromUserClaims(context.HttpContext, userStateType);
            }
        }