public byte[] GenerateCaptchaImageBytes(ISession httpSession, int width = 100, int height = 36)
        {
            EnsureHttpSession(httpSession);

            var captchaCode = GenerateCaptchaCode();
            var result      = CaptchaImageGenerator.GetImage(width, height, captchaCode);

            httpSession.SetString(Options.SessionName, result.CaptchaCode);
            return(result.CaptchaByteData);
        }
        public FileStreamResult GenerateCaptchaImageFileStream(ISession httpSession, int width = 100, int height = 36)
        {
            EnsureHttpSession(httpSession);

            var captchaCode = GenerateCaptchaCode();
            var result      = CaptchaImageGenerator.GetImage(width, height, captchaCode);

            httpSession.SetString(Options.SessionName, result.CaptchaCode);
            Stream s = new MemoryStream(result.CaptchaByteData);

            return(new FileStreamResult(s, "image/png"));
        }
예제 #3
0
        public FileStreamResult GenerateCaptchaImageFileStream(ISession httpSession, int width = 100, int height = 36)
        {
            if (null == httpSession)
            {
                throw new ArgumentNullException(nameof(httpSession),
                                                "Session can not be null, please check if Session is enabled in ASP.NET Core via services.AddSession() and app.UseSession().");
            }
            var captchaCode = GenerateCaptchaCode();
            var result      = CaptchaImageGenerator.GetImage(width, height, captchaCode);

            httpSession.SetString(Options.SessionName, result.CaptchaCode);
            Stream s = new MemoryStream(result.CaptchaByteData);

            return(new FileStreamResult(s, "image/png"));
        }