验证码精简版:
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; } } } }