public IActionResult GetCode() { //待返回对象 var result = new ResponseModel(ResponseCode.Success, "查询成功!"); //调用图片码 string randomCode = SecurityCode.CreateRandomCode(4); if (!string.IsNullOrEmpty(randomCode)) { //字符串加缓存 string keys = "ImageCode_Login" + DateTime.Now.ToString("yyyyMMddHHmmssfffffff");//Guid.NewGuid() TimeSpan ts1 = new TimeSpan(0, 5, 0); CacheManager.Create().Set(keys, randomCode, ts1); //读取图片 byte[] imgCode = SecurityCode.CreateValidateGraphic(randomCode); string base64str = Convert.ToBase64String(imgCode); var ImagCode = new { imgcode = "data:image/png;base64," + base64str, imgkey = keys, }; result.data = ImagCode; } return(Json(result)); }
public ActionResult GetSecurityCode() { SecurityCode code = new SecurityCode(); Session["skey"] = code.CreateRandomCode(4); byte[] buf = code.CreateValidateGraphic(Session["skey"].ToString()); return(File(buf, "image/Jpeg")); }
public ActionResult SecurityCode() { SecurityCode sc = new SecurityCode(); string oldcode = TempData["SecurityCode"] as string; string code = sc.CreateRandomCode(5); TempData["SecurityCode"] = code; return(File(sc.CreateValidateGraphic(code), "image/Jpeg")); }