动态加载验证码
来源:互联网 发布:抢车票软件 编辑:程序博客网 时间:2024/06/06 08:24
1.创建一般应用程序ashx
<%@ WebHandler Language="C#" Class="YZM" %>using System;using System.Web;public class YZM : IHttpHandler,System .Web.SessionState .IRequiresSessionState{ public void ProcessRequest (HttpContext context) { //动态生成图片 context.Response.ContentType = "image/JPEG"; using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(100, 30)) { using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) { /* g.DrawString("验证码", new System.Drawing.Font("宋体", 10), System.Drawing.Brushes .Red , new System.Drawing.PointF(0, 0)); bitmap .Save (context .Response .OutputStream ,System .Drawing.Imaging.ImageFormat .Jpeg) ; */ //动态产生随机数 Random rand = new Random(); int code = rand.Next(); string strCode = code.ToString(); HttpContext.Current.Session["Code"] = strCode; g.DrawString(strCode, new System.Drawing.Font("宋体", 12), System.Drawing.Brushes.Green, new System.Drawing.PointF(0, 0)); bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); } } } public bool IsReusable { get { return false; } } }
2.在aspx中调用Session中存储的验证码
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class 验证码 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string yzm = Convert.ToString(Session ["Code"]); Response.Write(yzm); if (yzm==TextBox1 .Text ) { Response.Write("验证码正确"); } else { Response.Write("验证码不正确,请重新输入"); TextBox1.Text = ""; } }}
- 动态加载验证码
- 动态库加载验证结论
- jQuery属性,验证码失效,动态内容加载
- 动态生成验证码
- 动态生成验证码
- 创建动态验证码
- 动态生成验证码
- 动态验证码
- C#动态验证码
- 动态验证码
- 动态生成验证码
- Java 动态验证码
- 动态生成验证码
- 动态验证码问题
- 动态生成验证码
- phpcms不能加载验证码
- ThinkPHP 验证码加ajax动态验证
- 动态生成验证码图片
- Java中的DatagramPacket与DatagramSocket的初步
- 国嵌Linux视频课件整理(2)
- 算法:将两套混在一起的扑克牌分开
- 找回了CSDN的密码了
- gnuplot使用技巧
- 动态加载验证码
- C++项目通过JNI使用Java第三方jar包
- 一个简单的ibatis.net架构(包含项目模板代码下载)
- u-boot移植(一)移植前准备
- 关于std::remove_if
- Rootkits技术_直接内核操作(1)
- Postfix介绍
- u-boot移植(二)建立mini2440开发板工程
- 1234