Page : GenerateCaptcha.aspx
protected void Page_Load(object sender, EventArgs e)
{
ClsWorkFlow objwork = new ClsWorkFlow();
string strCaptcha = objwork.Decrypt(Request.QueryString["cap"]);
Response.Clear();
int height = 30;
int width = 100;
Bitmap bmp = new Bitmap(width, height);
RectangleF rectf = new RectangleF(10, 5, 0, 0);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
Font f = new Font("Thaoma", 12, FontStyle.Italic);
g.DrawString(strCaptcha, f, Brushes.Red, rectf);
g.DrawRectangle(new Pen(Color.Red), 1, 1, width - 2, height - 2);
g.Flush();
Response.ContentType = "image/jpeg";
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
g.Dispose();
bmp.Dispose();
}
Call the page
public void FillCapctha()
{
try
{
Random random = new Random();
string combination = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
StringBuilder captcha = new StringBuilder();
for (int i = 0; i <= 6; i++)
{
captcha.Append(combination[random.Next(combination.Length)]);
}
ViewState["captcha"] = captcha.ToString();
helper obj = new helper();
ClsWorkFlow objwork = new ClsWorkFlow();
imgCaptcha.ImageUrl = "GenerateCaptcha.aspx?cap=" + ViewState["captcha"].ToString();
}
catch (Exception ex)
{
throw ex;
}
}
No comments:
Post a Comment