Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace WebApplication4
{
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Random r = new Random((int)DateTime.Now.Ticks);
int number = r.Next(1000, 9999);
Session["validateCode"] = number;
Bitmap bmp = new Bitmap(50, 25);
Graphics g = Graphics.FromImage(bmp);
HatchBrush hb = new HatchBrush(HatchStyle.Cross, Color.Green, Color.White);
g.FillRectangle(hb, 0, 0, 25, 50);
g.DrawString(number.ToString(), new Font("arial", 14), new SolidBrush(Color.Red), 0, 0);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
hb.Dispose();
g.Dispose();
bmp.Dispose();
Response.Flush();
}
}
}