aps.net的验证码

IRequiresSessionState加这一个解析不然显示不出来针对session

using (System.Drawing.Bitmap bitmp = new System.Drawing.Bitmap(150, 80))
        {
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmp))
            {
                Random rand = new Random();
                int code = rand.Next(1000,9999);
                string strcode = code.ToString();
              HttpContext.Current.Session["Code"] = strcode;
                g.DrawString(strcode, new System.Drawing.Font("宋体", 18), System.Drawing.Brushes.Green, new System.Drawing.PointF(0, 0));
                bitmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                
            }
        }

 

鼠标点击能够随机读取每一张不同的数字

<img src="yzm.ashx"  onclick="this.src='yzm.ashx?a='+new Date()"/>加一个时间

你可能感兴趣的:(.net)