您现在的位置是:首页
>
验证码给别人了怎么办 ValidNumber.ashx验证码
ValidNum er.a hx验证码 ValidNum er a hx 代码 lt %@ We Ha dler La guage= C# Cla = ValidNum er % gt u i g S
ValidNumber.ashx验证码

ValidNumber ashx 代码 <%@ WebHandler Language= C# Class= ValidNumber %> using System; using System Web; using System Web SessionState; //第一步 导入此命名空间 public class ValidNumber : IHttpHandler IRequiresSessionState { public void ProcessRequest(HttpContext context) { //种子 string[] strlist = new[] { a b c d q w e r t y u i o p z x n v W Q B A D D F G H J K L }; //生成随机数 string[] list = new string[ ]; Random rd = new Random(DateTime Now Millisecond * ) for (int i = ; i < ; i++) { list[i] = strlist[rd Next(strlist Length)]; System Threading Thread Sleep( ) } System Text StringBuilder sb = new System Text StringBuilder() for (int i = ; i < ; i++) { sb = sb Append(list[i]) } HttpContext Current Session[ validNumber ] = sb; //创建一张图片 System Drawing Bitmap image = new System Drawing Bitmap(list Length * ) //创建画布 System Drawing Graphics g = System Drawing Graphics FromImage(image) //清空背景色 并添充成白色 g Clear(System Drawing Color White) //噪声线 for (int i = ; i < ; i++) { Random rds = new Random() float x = rds Next(image Width ) float x = rds Next(image Width ) float y = rds Next(image Height ) float y = rds Next(image Height ) System Threading Thread Sleep( ) g DrawLine(new System Drawing Pen(System Drawing Color Silver) x y x y ) } System Drawing Font f = new System Drawing Font( 黑体 System Drawing GraphicsUnit Pixel) System Drawing Brush bs = new System Drawing SolidBrush(System Drawing Color Red) g DrawString(sb ToString() f bs ) //当前请求输出的类型 HttpContext Current Response ContentType = image/jpeg ; //保存到输出流 image Save(HttpContext Current Response OutputStream System Drawing Imaging ImageFormat Jpeg) g Dispose() image Dispose() } public bool IsReusable { get { return false; } } } 页面调用时 <img src= ValidNumber ashx alt= 图片验证码 /> 但是回发session值改变页面图片没变 暂无比较理想的解决办法 提交时后台用 Response Write( <script> window location href=window location href</script> ) 刷新下页面 lishixinzhi/Article/program/net/201311/13143
很赞哦! (1049)
相关文章
- 姓名身份证号码有效的 我想通过身份证号和姓名查找详细地址,怎么能查到
- 身份证号码格式错误是什么意思 会计信息采集发现原来会计证上身份证号码错误怎么办?
- 会计从业资格网上报名的编号不在了怎么办谢谢了,大神帮忙啊
- qq申诉中心网页 安全中心我想验证一下结果要需要以前手机号码才能验证手机号码都忘了 我是至尊宝使用者申诉不了怎么办
- 高通9008解锁 和田玉编码:oh900818代表什么意思 可以查到鉴定证书吗?说是有证书可以在网上查到。但是只要这个编号
- 身份证号码姓名公开 输入姓名和地址可以查询真实的身份证号码吗?
- 身份证号码格式不正确 身份证号码格式是什么?
- 姓名身份证号码有效的 怎样凭姓名查询身份证号码呢?
- 姓名身份证号码有效的 知道身份证号码和姓名可以查出详细地址吗?
- api接口异常怎么办 淘宝api签名异常,如何正确计算sign引数
爱学记

微信收款码
支付宝收款码