Esempio n. 1
0
        public IActionResult TestRedis()
        {
            cacheProvider.Set("username", new UserDto()
            {
                Username = "******"
            });
            UserDto user = cacheProvider.Get <UserDto>("username");

            if (user != null)
            {
                return(Content(JsonConvert.SerializeObject(SimpleResponseDto <bool> .OK(true)), "application/json", Encoding.UTF8));
            }
            return(Content(JsonConvert.SerializeObject(SimpleResponseDto <bool> .Failed(ResponseCodeEnum.ResponseCode_100)), "application/json", Encoding.UTF8));
        }
Esempio n. 2
0
        private bool ValidAccessToken(ActionExecutingContext context, string accessToken)
        {
            context.HttpContext.Items[AuthorizationHeaderName] = accessToken;
            if (cacheProvider == null)
            {
                cacheProvider = (IDisctributedCacheProvider)context.HttpContext.RequestServices.GetService(typeof(IDisctributedCacheProvider));
            }
            //get user from distributed cache
            User user = cacheProvider.Get <User>(accessToken);

            if (user != null)
            {
                //there, we can cache user object to http context.
                return(true);
            }
            return(false);
        }