zoukankan      html  css  js  c++  java
  • 生成验证码

    验证码精简版:

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Linq;
    using System.Web;
    using System.Web.SessionState;
    
    namespace Web_Cassini.Day6
    {
        /// <summary>
        /// generateValidCode 的摘要说明
        /// </summary>
        public class generateValidCode : IHttpHandler,IRequiresSessionState
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "image/jpeg";
                Random ran = new Random();
                int num = ran.Next(1000, 10000);
                context.Session[MyConstClass.LOGINVALIDCODE] = num.ToString();
    
                using(Bitmap map=new Bitmap(60,30))
                {
                    using(Graphics g=Graphics.FromImage(map))
                    using(Font font=new Font(FontFamily.GenericSerif,15))
                    {
                        g.DrawString(num.ToString(), font, Brushes.Red, 0, 0);
                    }
                    map.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                }
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
    验证码精简版
  • 相关阅读:
    17.10.13
    17.10.12
    17.10.11
    17.10.10
    17.10.05
    17.10.04
    17.10.03
    17.10.02
    17.10.01
    17.9.29
  • 原文地址:https://www.cnblogs.com/adolphyang/p/4804013.html
Copyright © 2011-2022 走看看