This paper describes the method of simple generation of verification code for ASP. Share to everyone for your reference, as follows:
1. Create a new generic handler
namespace webapplication1{//<summary>///$codebehindclassname $ for a summary description///</summary> [WebService ( Namespace = "http://tempuri.org/")] [webservicebinding (ConformsTo = wsiprofiles.basicprofile1_1)] public class Handler1:ihttphandler, irequiressessionstate {public void ProcessRequest (HttpContext context) {context. Response.ContentType = "Image/gif"; Create Bitmap object, plot Bitmap basemap = new Bitmap (100, 30); Graphics graph = graphics.fromimage (basemap); Graph. FillRectangle (New SolidBrush (Color.White), 0, 0, 100, 30); Font font = new Font (FONTFAMILY.GENERICSERIF, fontstyle.bold, GraphicsUnit.Pixel); Random r = new Random (); String letters = "ABCDEFGHIJKLMNPQRSTUVWXYZ"; String Letter; StringBuilder s = new StringBuilder (); Add a random five letters for (int x = 0; x < 5; + +) {letter = letters. Substring (r.next (0, letters. Length-1), 1); S.append (letter); Graph. DrawString (letter, font, New SolidBrush (Color.Black), X *, R.next (0, 8)); }//Confusing background Pen Linepen = new Pen (new SolidBrush (Color.Black), 2); for (int x = 0; x < 6; × x + +) graph. DrawLine (Linepen, New Point (R.next (0), R.next (0)), New Point (R.next (0,), R.next (0, 29)); Save the picture to the output stream basemap. Save (context. Response.outputstream, imageformat.gif); Context. session["Checkcode"] = s.tostring (); If IRequiresSessionState is not implemented, there will be an error here, and the picture context cannot be generated. Response.End (); } public bool IsReusable {get {return false; } } }}
2. Foreground code
It is hoped that this article will help you with ASP.