示例#1
0
        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);
        }
示例#2
0
        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);
        }