我用的是vs2010,在一般处理程序中写的代码,下面的代码能生成验证码吗??、using System;
using System.Collections.Generic;
using System.Web;namespace 练习1
{
/// <summary>
/// 验证码 的摘要说明
/// </summary>
public class YZM : IHttpHandler,System.Web.SessionState.IRequiresSessionState
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/JPEG";
using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(100, 50))
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
{
Random rand = new Random();
int code= rand.Next(1000,9999);
string strCode = code.ToString();
HttpContext.Current.Session["Code"] = strCode;
g.DrawString(strCode,new System.Drawing.Font("宋体",12),System.Drawing.Brushes.Red,new System.Drawing.PointF(0,0));
bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
} public bool IsReusable
{
get
{
return false;
}
}
}
}
using System.Collections.Generic;
using System.Web;namespace 练习1
{
/// <summary>
/// 验证码 的摘要说明
/// </summary>
public class YZM : IHttpHandler,System.Web.SessionState.IRequiresSessionState
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/JPEG";
using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(100, 50))
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
{
Random rand = new Random();
int code= rand.Next(1000,9999);
string strCode = code.ToString();
HttpContext.Current.Session["Code"] = strCode;
g.DrawString(strCode,new System.Drawing.Font("宋体",12),System.Drawing.Brushes.Red,new System.Drawing.PointF(0,0));
bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
} public bool IsReusable
{
get
{
return false;
}
}
}
}
用YZM.aspx试试,另外Class能不能不用中文。
<img src="YZM.ashx" />可以生成验证码啊,不知道楼主要干什么。