zoukankan
html css js c++ java
httphandler生成验证图
<%
@ WebHandler Language
=
"
C#
"
Class
=
"
image
"
%>
using
System;
using
System.Web;
using
System.Drawing;
public
class
image : IHttpHandler,System.Web.SessionState.IRequiresSessionState
{
public
void
ProcessRequest (HttpContext context)
{
context.Response.ContentType
=
"
text/gif
"
;
Bitmap b
=
new
Bitmap(
200
,
60
);
Graphics g
=
Graphics.FromImage(b);
g.FillRectangle(
new
SolidBrush(Color.White),
0
,
0
,
200
,
60
);
Font font
=
new
Font(FontFamily.GenericSansSerif,
48
, FontStyle.Bold, GraphicsUnit.Pixel);
Random r
=
new
Random();
string
letters
=
"
ABCDEFGHIJKMNPQRSTUVWXYX
"
;
string
letter;
System.Text.StringBuilder s
=
new
System.Text.StringBuilder();
for
(
int
x
=
0
; x
<
5
; x
++
)
{
letter
=
letters.Substring(r.Next(
0
, letters.Length
-
1
),
1
);
s.Append(letter);
g.DrawString(letter, font,
new
SolidBrush(Color.Black), x
*
38
, r.Next(
0
,
15
));
}
Pen linePen
=
new
Pen(
new
SolidBrush(Color.Black),
2
);
for
(
int
x
=
0
; x
<
6
; x
++
)
{
g.DrawLine(linePen,
new
Point(r.Next(
0
,
199
), r.Next(
0
,
59
)),
new
Point(r.Next(
0
,
199
), r.Next(
0
,
59
)));
}
b.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
context.Session[
"
aaa
"
]
=
s.ToString();
context.Response.End();
}
public
bool
IsReusable
{
get
{
return
false
;
}
}
}
<img src="image.ashx" />
查看全文
相关阅读:
stutas2配置action
Struts2 第一个入门小案例
spring与mybati整合方法
spring事务隔离级别以及脏读 不可重复读 幻影读
socket编程基础
ajax随笔
多线程基础
Mybatis中collection与association的区别
Guideline 2.3.1
苹果手机 apple pay 一不小心支付购买了自己不要的服务
原文地址:https://www.cnblogs.com/zwl12549/p/964728.html
最新文章
JQuery的工具trim()
“生产环境、沙盒环境”普及贴
详说jQuery的 val() 事件
详说jQuery的focus()、blur()事件
计算机基础知识-->计算机硬件-->硬件
计算机基础知识-->计算机硬件-->概述
Node入门--13-->Express
Node入门--12-->npm
MyBatis总结与复习
Oracle同义词。。。
热门文章
Oracle单行函数。。。
Oracle入门
POI 博客总结.....
在Controller方法执行之前进行捕获请求,进行类型的转换
面试题。。。。
任务:泛型集合十道面试题.
IoC和AOP使用扩展。。。
StringMVC返回字符串
Redis安装以及基本操作命令
Struts2与OGNL
Copyright © 2011-2022 走看看