Exemple #1
0
        public void ProcessRequest(HttpContext context)
        {
            var key       = Extensions._captchaPrefix + context.Request.QueryString["id"];
            var bmCaptcha = CaptchaManager.GenerateCaptchaImage(key);

            bmCaptcha.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
            context.Response.ContentType = "image/png";
            //context.Response.Write("Hello World");
        }
        public async Task ProcessRequestAsync(HttpContext context)
        {
            var key      = Extensions._captchaPrefix + context.Request.Query["id"];
            var cSetting = AppContext.Current.Session.Get <CaptchaSettings>(key);

            byte[] bytes = new byte[0];
            if (cSetting.EnableAudio)
            {
                bytes = await CaptchaManager.GenerateCurrentCaptachAudio(key);
            }
            context.Response.Clear();
            context.Response.ContentType = "audio/mp3";

            await context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
        }
Exemple #3
0
        public override async Task ProcessRequestAsync(HttpContext context)
        {
            //"".CreateAudio();

            var key      = Extensions._captchaPrefix + context.Request.QueryString["id"];
            var cSetting = (CaptchaSettings)HttpContext.Current.Session[key];

            byte[] bytes = new byte[0];
            if (cSetting.EnableAudio)
            {
                bytes = await CaptchaManager.GenerateCurrentCaptachAudio(key);
            }
            //var cbytes = bytes.CompressWav();
            context.Response.OutputStream.Write(bytes, 0, bytes.Length);
            context.Response.ContentType = "audio/mp3";
            //context.Response.Write("Hello World");
        }
Exemple #4
0
        public async Task ProcessRequestAsync(HttpContext context)
        {
            var key = Extensions._captchaPrefix + context.Request.Query["id"];

            Stream originalBody = context.Response.Body;

            try
            {
                using (var image = await CaptchaManager.GenerateCaptchaImage(key))
                    using (var memStream = new MemoryStream())
                    {
                        image.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);
                        context.Response.Body = memStream;

                        memStream.Position = 0;
                        await memStream.CopyToAsync(originalBody);
                    }
            }
            finally
            {
                context.Response.Body = originalBody;
            }
        }