コード例 #1
0
        public ActionResult CaptchaImage()
        {
            var cp    = new LiteralCaptcha(50, 30, 4);
            var bytes = cp.Generate();

            Session["captcha"] = cp.Result;
            return(File(bytes, "image/Jpeg"));
            //return img;
        }
コード例 #2
0
        /// <summary>
        /// 登录验证码
        /// </summary>
        /// <returns></returns>
        public FileContentResult CaptchaImage()
        {
            var captcha = new LiteralCaptcha(80, 25, 4);
            var bytes   = captcha.Generate();
            //验证码插入Redis缓存
            var    redis    = new ETS.NoSql.RedisCache.RedisCache();
            string cachekey = string.Format(RedissCacheKey.CaptchaImage, ETS.Util.Helper.Uuid());

            redis.Add(cachekey, captcha.Captcha, DateTime.Now.AddHours(10));
            //缓存key放入cookie里存储
            CookieHelper.WriteCookie("Cookie_Verification", cachekey, DateTime.Now.AddMinutes(10));
            return(new FileContentResult(bytes, "image/jpeg"));;
        }