ZSJ_BCY_Web/ASHX/ImgAuth.ashx.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using  System.Drawing;
using System.Web.SessionState;

namespace ZSJ_BCY_Web.ASHX
{
    /// <summary>
    /// ImgAuth 的摘要说明
    /// </summary>
    public class ImgAuth : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            using (Bitmap bitmap = new Bitmap(60, 30))
            {
                using (Font f = new Font("宋体", 20))
                {
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        Random r = new Random();
                        int validata = r.Next(1000, 9999);//随机生成四位纯数字的验证码
                        context.Session["code"] = validata;//保存在Session内置对象中
                        g.DrawString(validata.ToString(), f, Brushes.Red, new PointF(0, 0));
                    }
                }
                bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。