コード例 #1
0
        public HttpResponseMessage GetValidateCode(string sid)
        {
            string code = RandomStringGenerator.CreateRandomNumeric(5);
            var    resp = new HttpResponseMessage();

            try
            {
                if (string.IsNullOrEmpty(sid) || sid.Length < 32)
                {
                    resp.StatusCode = HttpStatusCode.BadRequest;
                }
                else
                {
                    CacheProvider.Set("vcode." + sid, code, TimeSpan.FromMinutes(10));
                    byte[] buffer = ValidateCodeGenerator.CreateImage(code);
                    resp.Content = new ByteArrayContent(buffer);
                    resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
                }
            }
            catch
            {
                resp.StatusCode = HttpStatusCode.InternalServerError;
            }

            return(resp);
        }
コード例 #2
0
ファイル: SiteController.cs プロジェクト: HZI-carol/junxi-web
        public ActionResult VerifyCode()
        {
            string code = RandomStringGenerator.CreateRandomNumeric(5);

            byte[] buffer = ValidateCodeGenerator.CreateImage(code);
            Session["vcode"] = code;

            return(File(buffer, "image/png"));
        }