zoukankan
html css js c++ java
.net 点击刷新验证码问题
验证码生成文件:
validate.aspx.cs
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.IO;
using
System.Drawing;
using
System.Drawing.Imaging;
using
System.Drawing.Drawing2D;
public
partial
class
validate : System.Web.UI.Page
{
private
Bitmap validateimage;
private
Graphics g;
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack)
{
string
VNum
=
MakeValidateCode();
Session[
"
VNum
"
]
=
VNum;
ValidateCode(VNum);
}
}
public
void
ValidateCode(
string
VNum)
{
validateimage
=
new
Bitmap(
60
,
15
, PixelFormat.Format24bppRgb);
g
=
Graphics.FromImage(validateimage);
g.FillRectangle(
new
LinearGradientBrush(
new
Point(
0
,
0
),
new
Point(
110
,
20
), Color.FromArgb(
240
,
255
,
255
,
255
), Color.FromArgb(
240
,
255
,
255
,
255
)),
0
,
0
,
200
,
200
);
g.DrawString(VNum,
new
Font(
"
arial
"
,
11
),
new
SolidBrush(Color.Red),
new
PointF(
6
,
0
));
g.Save();
MemoryStream ms
=
new
MemoryStream();
validateimage.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.ContentType
=
"
image/bmp
"
;
Response.BinaryWrite(ms.ToArray());
Response.End();
}
string
MakeValidateCode()
{
char
[] s
=
new
char
[]
{
'
0
'
,
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
,
'
5
'
,
'
6
'
,
'
7
'
,
'
8
'
,
'
9
'
,
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
,
'
e
'
,
'
f
'
,
'
g
'
,
'
h
'
,
'
i
'
,
'
j
'
,
'
k
'
,
'
l
'
,
'
m
'
,
'
n
'
,
'
o
'
,
'
p
'
,
'
q
'
,
'
r
'
,
'
s
'
,
'
t
'
,
'
u
'
,
'
v
'
,
'
w
'
,
'
x
'
,
'
y
'
,
'
z
'
,
'
A
'
,
'
B
'
,
'
C
'
,
'
D
'
,
'
E
'
,
'
F
'
,
'
G
'
,
'
H
'
,
'
I
'
,
'
J
'
,
'
K
'
,
'
L
'
,
'
M
'
,
'
N
'
,
'
O
'
,
'
P
'
,
'
Q
'
,
'
R
'
,
'
S
'
,
'
T
'
,
'
U
'
,
'
V
'
,
'
W
'
,
'
X
'
,
'
Y
'
,
'
Z
'
}
;
string
num
=
""
;
Random r
=
new
Random();
for
(
int
i
=
0
; i
<
4
; i
++
)
{
num
+=
s[r.Next(
0
, s.Length)].ToString();
}
return
num;
}
}
在页面中调用:
<
img
src
="../validate.aspx"
id
="yzm"
onclick
="this.src='../validate.aspx?abc='+Math.random()"
alt
="图片看不清?点击重新得到验证码"
style
="cursor:hand;"
/>
注意:有一点要说明,当点击刷新时,validate.asp?后面一定要有一个参数,若没有这个无效的参数,程序会认为你请求的是同一个文件,因而不会刷新的。这里的参数abc是个随意的,只起改变请求文件的作用。
本人博客的文章大部分来自网络转载,因为时间的关系,没有写明转载出处和作者。所以在些郑重的说明:文章只限交流,版权归作者。谢谢
查看全文
相关阅读:
spring boot的application配置文件
C# WinForm 中英文实现, 国际化实现的简单方法
VS2012 2013 显示查找功能 无法具体定位 解决方法
C#使用HttpWebRequest 进行请求,提示 基础连接已经关闭: 发送时发生错误。
VS 默认开发环境如何更改
C# winfrom HttpWebRequest 请求获取html网页信息和提交信息
C# 定时器 Timers.Timer Forms.Timer
HTTP 错误 500.21
配置iis时,浏览项目提示 无法识别的属性“targetFramework”。请注意属性名称区分大小写。
asp xml对象转换为string
原文地址:https://www.cnblogs.com/wzg0319/p/1415385.html
最新文章
解决python2.7 import ujson问题
UNIX标准文件编程库的常用函数
合并K个有序数组-Java
生产者消费者模型-Java代码实现
Failed to register dubbo:
gradle-在一个模块中引入其它模块
thymeleaf:在一个页面中引入其它的页面
thymeleaf实现热部署
Push to origin/master was rejected
弗洛伊德算法(Floyd )
热门文章
迪杰斯特拉算法(计算路径)
mysql索引数据结构
mysql 执行计划查看
mysql索引最佳实践
MyISAM与InnoDB的区别
spring boot使用拦截器
spring boot事务管理
spring boot集成mybatis
spring boot集成jsp
spring boot自定义配置
Copyright © 2011-2022 走看看