asp.net一般处理程序(.ashx)动态生成验证码案例。
2020-11-15 07:37
标签:http div img code tar ext width string strong c int {使用一般处理程序动态生成验证码} 1.新建WebSite项目,添加一般处理程序命名为 yzm.ashx,添加如下代码: public void ProcessRequest(HttpContext context)
//将context.Response.ContentType = "text/plain";修改为context.Response.ContentType =
"image/JPEG";
//测试示例
System.Drawing.Pen pen =
(System.Drawing.Pen)
bitmap.Save(context.Response.OutputStream,
//生成随机数
//存session
}
//本身就有的 2.新建webApplication。 在 添加TextBox 和Button,Button的单击事件如下 protected void Button1_Click(object sender, EventArgs
e) 3.随后即可在WebApplication中进行测试。 asp.net一般处理程序(.ashx)动态生成验证码案例。,布布扣,bubuko.com asp.net一般处理程序(.ashx)动态生成验证码案例。 标签:http div img code tar ext width string strong c int 原文地址:http://www.cnblogs.com/fanshaomin/p/3697457.html
{
context.Response.ContentType =
"image/JPEG";
using
(System.Drawing.Bitmap bitmap
=
new System.Drawing.Bitmap(150,
50))
{
using
(System.Drawing.Graphics grapgics
=
System.Drawing.Graphics.FromImage(bitmap))
{
/*grapgics.DrawString("哈喽",
new System.Drawing.Font("宋体",
20),
System.Drawing.Brushes.Blue
, new System.Drawing.PointF(0,
0));
System.Drawing.Pens.Red.Clone();
pen.Width =
3;
grapgics.DrawEllipse(pen, new System.Drawing.Rectangle(20, 20, 10,
10));
System.Drawing.Imaging.ImageFormat.Jpeg);*/
Random random = new
Random();
int code =
random.Next();
string strCode = code.ToString();
HttpContext.Current.Session["code"] =
strCode;
grapgics.DrawString(strCode,
new System.Drawing.Font("宋体",
20),
System.Drawing.Brushes.Blue
, new System.Drawing.PointF(0,
0));
bitmap.Save(context.Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);
}
context.Response.Write("Hello World");
}
{
string
stryzm =
Convert.ToString(Session["code"]);
if (stryzm==TextBox1.Text)
{
Response.Write("正确");
}
else
{
Response.Write("错误");
}
}
上一篇:什么是PHP?如何学好PHP?
文章标题:asp.net一般处理程序(.ashx)动态生成验证码案例。
文章链接:http://soscw.com/essay/21412.html