Beispiel #1
0
        public JsonResult CreateValidateCode()
        {
            //首先实例化验证码的类
            ValidateCodeHelper validateCode = new ValidateCodeHelper();
            //生成验证码指定的长度
            string code = validateCode.GetRandomString(4);
            //创建验证码的图片
            var base64Str = validateCode.CreateImage(code);
            var token     = Guid.NewGuid().ToString("N");

            using (RedisClient redisClient = RedisHelper.CreateClient())
            {
                redisClient.Set(token, code, TimeSpan.FromMinutes(5));
            }
            return(Json(new
            {
                base64Str,
                token
            }));
        }