Completing an In-Text Advertising System under an ASP.NET 3.5 Environment - The Verification Code
(Page 2 of 5 )
As hinted above, the verification code is generated through the "Gif.aspx" page. Looking closely, you will find that the HTML coding of this page is empty, and all of the implementation logic is performed by invoking the ValidateCode server-side class, with which we generate the verification code-related picture. Below I've given the code for the gif.aspx.cs file:
protected void Page_Load(object sender, EventArgs e)
{
ValidateCode gif=new ValidateCode ();//verifying code
string valid ="";
MemoryStream ms = gif.Create ( out valid);
Session["sdf"] = valid;//store the verifying code
//first empty
Response.ClearContent();
Response.ContentType = "image/png";
Response.BinaryWrite(ms.ToArray());//output in the picture format
Response.End();
}
The principle used to generate the verifying code is: first generate a random number; use this number to generate a picture; put the picture into the memory stream; and finally output the picture from the memory stream to the web page. Since the implementation of the ValidateCode class is so tedious to code, we will not list it; you can refer to the downloadable source code for the details.
Next: The Member Center: the siteUser.aspx page >>
More ASP.NET Articles
More By Xianzhong Zhu