1 usingSystem;2 usingsystem.web;3 usingSystem.Drawing;4 usingSystem.Web.SessionState;//ireqiressessionstate Namespaces5 //Click on the image for verification code with ImageButton, not available on the page add? Id=6 PublicCladd show:ihttphandler,irequiressessionstate7 {8Context. Response.contenttype="Image/jpeg";//the type to output9Bitmap img =NewBitmap ( -, -);//Create a blank chartTenGraphics gr=graphics.fromimage (IMG);//draw on that graph OneFont font =NewFont ("Song Body", A, FontStyle.Bold);//Set Font ASolidBrush brush =NewSolidBrush (Color.White);//Set Brush -Erl fillrectangle= (Brush,0,0, -, -);//The shape the brush draws -Brush. color=color.red;//Color the - - strings ="1234567890zxcvbnmasdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP"; - stringStr=""; +Radom rand =NewRandom ();//Initialize random number - string[]arr=New string[4]; + for(intI=0;i<4; i++)? A { atArr[i] =rand. Next ( +);//generates the starting position of a random number - intCont=0; - if(i>0) - { - for(intj=0; j<i;j++) - { in if(arr[i]==Arr[j]) - { tocount++; + } - } the } * if(count>0) $ {Panax Notoginsengi--; - Continue; the } +Str +=s.substring (Arr[i],1). ToString (); A } theContext. session["Yanzheng"]=str; +Erl DrawString (Str,font,brush,0,0);//finished drawing the picture - $ //Save The picture with the response response stream $ img. Save (context. RESPONSE.OUTPUTSTREAM,SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.JPEG); - Public BOOLisreusable - { the Get - {Wuyi return false; the } - } Wu } - //Default.aspx.cs About //write in Botton $ if(textbox3.text==session["Yanzheng"]. ToString ()) - { -Response.redirest ("page to jump from") -}View Code
WebForm Verification Code