ValidNumber. ashx code:
<% @ WebHandler Language = "C #" Class = "ValidNumber" %>
Using System;
Using System. Web;
Using System. Web. SessionState; // Step 1: import the namespace
Public class ValidNumber: IHttpHandler, IRequiresSessionState
{
Public void ProcessRequest (HttpContext context)
{
// Seed
String [] strlist = new []
{
"A", "B", "c", "d", "1", "2", "3", "4", "5", "6 ", "7", "8", "9", "0", "q", "w", "e", "r", "t", "y ", "u", "I", "o", "p", "z", "x", "n", "v", "W", "Q ", "B", "A", "D", "D", "F", "G", "H", "J", "K", "L"
};
// Generate a random number
String [] list = new string [4];
Random rd = new Random (DateTime. Now. Millisecond * 100000 );
For (int I = 0; I <4; I ++)
{
List [I] = strlist [rd. Next (strlist. Length)];
System. Threading. Thread. Sleep (5 );
}
System. Text. StringBuilder sb = new System. Text. StringBuilder ();
For (int I = 0; I <4; I ++)
{
Sb = sb. Append (list [I]);
}
HttpContext. Current. Session ["validNumber"] = sb;
// Create an image
System. Drawing. Bitmap image = new System. Drawing. Bitmap (list. Length * 15, 40 );
// Create a canvas
System. Drawing. Graphics g = System. Drawing. Graphics. FromImage (image );
// Clear the background color and add it to white
G. Clear (System. Drawing. Color. White );
// Noise line
For (int I = 0; I <20; I ++)
{
Random rds = new Random ();
Float x1 = rds. Next (image. Width-1 );
Float x2 = rds. Next (image. Width-1 );
Float y1 = rds. Next (image. Height-1 );
Float y2 = rds. Next (image. Height-1 );
System. Threading. Thread. Sleep (5 );
G. DrawLine (new System. Drawing. Pen (System. Drawing. Color. Silver), x1, y1, x2, y2 );
}
System. Drawing. Font f = new System. Drawing. Font ("", 25, System. Drawing. GraphicsUnit. Pixel );
System. Drawing. Brush bs = new System. Drawing. SolidBrush (System. Drawing. Color. Red );
G. DrawString (sb. ToString (), f, bs, 5, 5 );
// Current request output type
HttpContext. Current. Response. ContentType = "image/jpeg ";
// Save it to the output stream
Image. Save (HttpContext. Current. Response. OutputStream, System. Drawing. Imaging. ImageFormat. Jpeg );
G. Dispose ();
Image. Dispose ();
}
Public bool IsReusable
{
Get
{
Return false;
}
}
}
but the page image does not change when the session value is sent back. There is no ideal solution at the moment. Response is used in the background for submission. write ("<script> window. location. href = window. location. href </script> ") refresh the page. Thank you for your advice. Is there any better usage.
From column BQL_Email