public ActionResult VerifyImage() { var validate = new ValidateCodeUtil(); string code = validate.CreateValidateCode(4); byte[] bytes = validate.CreateValidateGraphic(code); var file = File(bytes, @"image/jpeg"); //验证码写入cookie return(file); }
public HttpResponseMessage VerifyImage() { var validate = new ValidateCodeUtil(); string code = validate.CreateValidateCode(4); byte[] bytes = validate.CreateValidateGraphic(code); //从图片中读取流 var resp = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(bytes) }; resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); return(resp); }