WebForm Verification Code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.