I am rolling my own captcha, since recaptcha is prooving to be a bit complex for a client’s visitors.
I have the following code:
private Bitmap generateCaptchaNumbers()
{
Random num1 = new Random();
Random num2 = new Random();
int numQ1;
int numQ2;
string QString;
numQ1 = num1.Next(10, 15);
numQ2 = num2.Next(10, 15);
QString = numQ1.ToString() + " + " + numQ2.ToString() + " = ";
_answer = numQ1 + numQ2;
Bitmap bmp = new Bitmap(85, 35);
Graphics gfx = Graphics.FromImage(bmp);
Font font = new Font("Arial", 18, FontStyle.Bold, GraphicsUnit.Pixel);
Rectangle rect = new Rectangle(0, 0, 100, 50);
gfx.FillRectangle(Brushes.White, rect);
gfx.DrawString(QString, font, Brushes.Blue, 0, 0);
return bmp;
}
How would I go about showing the generated bmp inside my registration usercontrol?
I would rather not need to save the generated bmp to disk, if possible.
You have to create a HttpHandler implementing the IHttpHandler and return the binary inside the ProcessRequest:
UPDATE: Follow this link to create and deploy a custom HttpHandler: http://support.microsoft.com/kb/308001