/// <summary> /// 获取验证码 /// </summary> /// <returns></returns> public ActionResult yzm() { ValidateCodeHelper vch = new ValidateCodeHelper(); string code = vch.GetRandomNumberString(4); Tools.WriteCookie("loginCode", code, 2); return(File(vch.CreateImage(code), "image/jpeg")); }
public FileResult ValidateCode() { ValidateCodeHelper validateCode = new ValidateCodeHelper(); string code = validateCode.GetRandomNumberString(4); TempData[VALIDATECODE] = code; byte[] bytes = validateCode.CreateImage(code); return(File(bytes, @"image/jpeg")); }
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 })); }