zoukankan      html  css  js  c++  java
  • 验证码测试

    1 调用

    <img src="Handler1.ashx" onclick="this.src='Handler1.ashx?aa='+new Date()" />

    2.生成图片的Handler1.ashx

      public class Handler1 : IHttpHandler,IRequiresSessionState
        {

            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "image/JPEG";
                using (Bitmap bp = new Bitmap(100, 50))
                {
                    using (Graphics g = Graphics.FromImage(bp))
                    {
                        Random r = new Random();
                        int code = r.Next(1000, 9999);
                        string strCode = code.ToString();
                        HttpContext.Current.Session["code"]=strCode;
                        g.DrawString(strCode,new System.Drawing.Font("宋体",12),Brushes.Green,new System.Drawing.PointF(0,0));
                        bp.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                }
            }

       注意:a.IRequiresSessionState必须要实现这个接口,为了调用 HttpContext.Current.Session["code"]=strCode

        b.aa='+new Date()"为了单机图片时,能刷新验证码图片

  • 相关阅读:
    《C》指针
    《C》变量
    《C》数组
    《C》VS控制台应用
    listagg wm_concat 行转列
    Linux学习之shell script
    Linux学习之正则表达式sed
    Linux学习之正则表达式grep
    Linux学习之SAMBA共享(密码验证)
    Linux学习之SAMBA共享(无密码)
  • 原文地址:https://www.cnblogs.com/ChineseMoonGod/p/3957270.html
Copyright © 2011-2022 走看看