html页面
ashx页面,一般处理程序页面:
<form id="form1" runat="server">
<img src="Handler2.ashx" onclick="this.src='Handler2.ashx?aaa='+new Date()" />
</form>
ashx页面,一般处理程序页面:
public class Handler2 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//context.Response.ContentType = "text/html";//返回一个text的东西,也就是string
context.Response.ContentType = "image/JPEG";
using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(100, 50))//(100,50)是大小
{
using(System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap) )
{
Random rand = new Random();
int code = rand.Next(1111, 2222);
string mycode = code.ToString();
// HttpContext.Current.Session["code_yes"] = mycode;
g.DrawString(mycode,new System.Drawing.Font("宋体",50),System.Drawing.Brushes.Green,new System.Drawing.PointF(0,0));
bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}