Create a new GetCode. aspx page and paste the following code in the GetCode. aspx. cs code file:
Using System;
Using System. Collections;
Using System. Configuration;
Using System. Data;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. HtmlControls;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Drawing;
Using System. Drawing. Drawing2D;
Public partial class WebControl_GetCode: System. Web. UI. Page
{
Const int number = 5;
String checkCode = "";
Protected void Page_Load (object sender, EventArgs e)
{
CheckCode = "";
DrawStr (RandomString ());
Session ["GetCode"] = checkCode;
}
// Used to generate random letters and numbers
Private string RandomString ()
{
String str = "2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, J, K, L, M, N, P, q, R, S, T, U, V, W, X, Y, Z ";
String [] strArray = str. Split ('','');
String codeStr = "";
Random ran = new Random ();
String s = "";
For (int I = 0; I <number; I ++)
{
S = strArray [ran. Next (30)];
CheckCode + = s;
CodeStr + = "" + s;
}
CodeStr + = "";
Return codeStr;
}
// Draw
Private void DrawStr (string codeStr)