验证码精简版:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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; } } } }