asp.net 的 handler 实现 验证码 、、
来源:互联网 发布:电脑笔记 知乎 编辑:程序博客网 时间:2024/05/14 09:16
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web.SessionState;
public class Handler : IHttpHandler,IRequiresSessionState {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "image/jpeg";
Random rand = new Random(DateTime.Now.Millisecond*1000000);
String[] list = { "2", "3", "5", "6", "A", "f", "h", "j", "q", "v","B","P" };
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 4; i++)
{
sb.Append(list[rand.Next(0, list.Length)]);
}
String number=sb.ToString();
context.Session["number"] = number.ToLower();
Image image = new Bitmap(number.Length * 30,40);
Font f=new Font("黑体",30);
Brush b=new SolidBrush(Color.White);
Graphics g = Graphics.FromImage(image);
g.Clear(Color.Black);
g.DrawString(number, f, b, 4, 4);
g.DrawRectangle(new Pen(Color.Yellow,1),1,1,image.Width-3,image.Height-3);
for (int i = 0; i < 20; i++)
{
Pen p = new Pen(Color.FromArgb(rand.Next(50, 255),rand.Next(50,255),rand.Next(50,255)));
int x1 = rand.Next(1,image.Width);
int y1 = rand.Next(1,image.Height);
int x2 = rand.Next(1,image.Width);
int y2 = rand.Next(1,image.Height);
g.DrawLine(p,x1,y1,x2,y2);
}
image.Save(context.Response.OutputStream,ImageFormat.Jpeg);
image.Dispose();
g.Dispose();
}
public bool IsReusable {
get {
return false;
}
}
}
using System;
using System.Web;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web.SessionState;
public class Handler : IHttpHandler,IRequiresSessionState {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "image/jpeg";
Random rand = new Random(DateTime.Now.Millisecond*1000000);
String[] list = { "2", "3", "5", "6", "A", "f", "h", "j", "q", "v","B","P" };
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 4; i++)
{
sb.Append(list[rand.Next(0, list.Length)]);
}
String number=sb.ToString();
context.Session["number"] = number.ToLower();
Image image = new Bitmap(number.Length * 30,40);
Font f=new Font("黑体",30);
Brush b=new SolidBrush(Color.White);
Graphics g = Graphics.FromImage(image);
g.Clear(Color.Black);
g.DrawString(number, f, b, 4, 4);
g.DrawRectangle(new Pen(Color.Yellow,1),1,1,image.Width-3,image.Height-3);
for (int i = 0; i < 20; i++)
{
Pen p = new Pen(Color.FromArgb(rand.Next(50, 255),rand.Next(50,255),rand.Next(50,255)));
int x1 = rand.Next(1,image.Width);
int y1 = rand.Next(1,image.Height);
int x2 = rand.Next(1,image.Width);
int y2 = rand.Next(1,image.Height);
g.DrawLine(p,x1,y1,x2,y2);
}
image.Save(context.Response.OutputStream,ImageFormat.Jpeg);
image.Dispose();
g.Dispose();
}
public bool IsReusable {
get {
return false;
}
}
}
- asp.net 的 handler 实现 验证码 、、
- ASP.Net实现图片的验证码
- asp.net中验证码的实现
- ASP.NET 验证码的实现
- ASP.NET实现简单的验证码
- asp.net中验证码的实现
- asp.net中验证码的实现
- ASP.NET图片验证码的实现
- ASP.NET图片验证码的实现
- asp.net中验证码的实现
- ASP.NET图片验证码的实现
- 【ASP.NET】验证码的实现
- asp.net验证码的实现
- ASP.Net实现验证码
- ASP.Net实现验证码
- ASP.Net实现验证码!
- asp.net实现验证码
- ASP.Net实现验证码
- 开发和部署SOE的步骤
- 【Boost】boost库中thread多线程详解2——mutex与lock
- Android service跨进程调用和启动检查
- It doesn't matter 应该怎么翻?
- freebsd 添加用户(组)
- asp.net 的 handler 实现 验证码 、、
- [设计模式]visitor访问者模式
- VC 使用OnCtlColor函数来改变控件颜色 .
- 1.1
- 机制与策略
- asp.net中,用LODOP打印用法示例!
- 对I2C总线时序的一点理解以及ACK和NACK(NAK)
- HDU3038 How Many Answers Are Wrong
- Android AIDL跨进程调用Service