schangxiang@126.com
2025-09-17 a32e5a5b296cab5ccc20953ca4e801ca4f27bd85
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.SessionState;
using System.Drawing.Imaging;
 
namespace FineUIPro.iWareWms
{
    /// <summary>
    /// 生成验证码图片
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class captcha : IHttpHandler, IReadOnlySessionState
    {
 
        public void ProcessRequest(HttpContext context)
        {
            int width = 200;
            int height = 30;
 
            try
            {
                width = Convert.ToInt32(context.Request.QueryString["w"]);
                height = Convert.ToInt32(context.Request.QueryString["h"]);
            }
            catch (Exception)
            {
                // Nothing
            }
 
            // 从 Session 中读取验证码,并创建图片
            CaptchaImage.CaptchaImage ci = new CaptchaImage.CaptchaImage(context.Session["CaptchaImageText"].ToString(), width, height, "Consolas");
 
            // 输出图片
            context.Response.Clear();
            context.Response.ContentType = "image/jpeg";
 
            ci.Image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
 
            ci.Dispose();
        }
 
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}