Explicación detallada de cómo implementar la función del código de verificación en VS2005 asp.net
Su archivo cs de fondo tiene el siguiente código:
PageLoad
privatevoid Page_Load (objeto remitente, Sistema.
{
string checkCode = CreateRandomCode(4);
Sesión["CheckCode"] = checkCode;
CreateImage(checkCode);
}<
Entre ellos, CreateRandomCode es una función personalizada cuyos parámetros representan el número de dígitos del código de verificación
privatestring CreateRandomCode(int codeCount). )
{
cadena allChar = "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,x,y,z";
cadena [ ] allCharArray = allChar.Split(',');
string randomCode = "";
int temp = -1;
Aleatorio rand = nuevo Aleatorio ();
for(int i = 0; i < codeCount; i++)
{
if(temp != -1)
{
rand = new Random(i*temp*((int)DateTime.Now.Ticks));
}
int t = rand.Next(35);
if(temp == t)
{
return CreateRandomCode(codeCount);
}
temp = t;
código aleatorio += allCharArray[t];
}
devuelve código aleatorio;
}
CreateImage también es una función personalizada para generar gráficos
privatevoid CreateImage(string checkCode)
{
int iwidth = ( int)(checkCode.Length * 11.5);
System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 20);
Gráficos g = Gráficos .FromImage( imagen);
Fuente f = new System.Drawing.Font("Arial.
Pincel b = new System.Drawing.SolidBrush(Color.White);
p >// Pincel b = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold
);