Step 1: generate a verification code
Add a ValidateCode. aspx page
The code in ValidateCode. aspx. cs is as follows:
Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Drawing;
Using System. Drawing. Imaging;
Public partial class ValidateCode: System. Web. UI. Page
{// This page will be used to generate a verification code Image
Protected void Page_Load (object sender, EventArgs e)
{// Call the function to generate an image of the Verification Code
This. CreateCheckCodeImage (GenerateCheckCode ());
}
Private string GenerateCheckCode ()
{// Generate a five-digit random string
Int number;
Char code;
String checkCode = String. Empty;
System. Random random = new Random ();
For (int I = 0; I <5; I ++)
{
Number = random. Next ();
If (number % 2 = 0)
Code = (char) ('0' + (char) (number % 10 ));