<%@ WebHandler language="C #"class="Show"%>usingSystem;usingsystem.web;usingSystem.Drawing;usingSystem.Web.SessionState;//IRequiresSessionState Namespaces Public classShow:ihttphandler, irequiressessionstate{ Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Image/jpeg";//the type to outputBitmap img=NewBitmap ( -, -);//Create a blank chartGraphics gr = Graphics.fromimage (IMG);//which map to draw onFont font =NewFont ("Song Body", A, FontStyle.Bold);//Set FontSolidBrush brush =NewSolidBrush (Color.White);//Set BrushErl FillRectangle (Brush,0,0, -, -);//The shape the brush drawsBrush. Color = color.red;//Color strings ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; stringstr =""; Random Rand=NewRandom ();//Initialize random number for(inti =0; I <4; i++) { intstart = Rand. Next ( +);//generate a random start positionstr + = s.substring (Start,1). ToString (); } context. session["Yanzheng"] =str; Erl DrawString (str, font, brush,0,0);//finished drawing the picture.//Save The picture with the response response streamimg. Save (context. RESPONSE.OUTPUTSTREAM,SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.JPEG); } Public BOOLisreusable {Get { return false; } }}
Web Verification Code Writing