登录论坛 | 注册会员 设为首页 | 收藏本站
当前位置 : 首页>软件学院>程序开发>ASP.NET>正文
 
asp.net实现验证码

http://www.dbit.cn 2008-6-29 21:21:23  来源:本站  编辑:张贺兵
 
  #region 实现一个验证码的类

  public class ValidateCode

  {

  private Bitmap validateimage;

  private Graphics g;

  public ValidateCode()

  {

  validateimage = new Bitmap(120, 30, PixelFormat.Format24bppRgb);

  g = Graphics.FromImage(validateimage);

  }

  public void DrawValidateCode(Page e, string i)

  {

  g.DrawString(i, new Font("黑体",16,FontStyle.Bold),new SolidBrush(Color.White),new PointF(2,4));

  g.FillRectangle(new LinearGradientBrush(new Point(0,0), new Point(120,30), Color.FromArgb(0,0,0,0),Color.FromArgb(255,255,255,255)),0,0,120,30);

  //validateimage.Save(e.OutputStream, ImageFormat.Jpeg);

  g.Save();

  MemoryStream ms=new MemoryStream();

  validateimage.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);

  e.Response.ClearContent();

  e.Response.ContentType="image/gif";

  e.Response.BinaryWrite(ms.ToArray());

  e.Response.End();

  //validateimage.Save(e.MapPath("NumImage/ValidateImage.gif"), ImageFormat.Gif);

  //e.End();

  }

  }

  

  #endregion

  private void 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 < 5; i++)

  {

  num += s[r.Next(0, s.Length)].ToString();

  }

  ((LoginUserInfo)Session["LoginUserInfo"]).ValidateNum = num;

  TextBox3.Text = "";

  }

  调用上面的类即可成功检测验证码.
 
收藏】【打印】【进入论坛
  相关文章:

·浅析五大ASP.NET数据控件
·Discuz!NT 3.1 为ASP.net社区提速 
·浅析五大ASP.NET数据控件
·ASP.NET全局异常处理的方法
·ASP.NET中在线用户统计
·用ASP.NET加密口令
·在ASP.NET中使用Microsoft Word文档
·Asp.net+Xml开发网络硬盘 
·用ASP.NET构建简单的Web Form 
·ASP.Net中自定义Http处理及应用之HttpModul
·用ASP.NET开发Web服务的五则技巧

 
 
 
 
最新文章

中关村艳照门女主角详记录高清组图 
大连护士门大尺度艳照高清组图
iPhone女孩微博爆红 最宝贵东西换iPhon
反恐精英之父内维尔:改变电脑游戏销售
团购网站黎明之前:中国市场惨烈厮杀不
团购鼻祖Groupon中国揭秘:快与慢的商业
Spil Games发布新的品牌形象
1800配置一台主机 不要显示器
联想V360笔记本模特写真
爱国者第四代移动硬盘将面市、低电压保

 
推荐文章
1
2
3
4
5
6
7
8
9
10
iPhone女孩微博爆红 最宝贵东西换
大连护士门大尺度艳照高清组图
中关村艳照门女主角详记录高清组
苹果员工中毒门
宫如敏不雅照疯传 看张馨予韩一菲
深耕市场 永续经营——专访百脑汇
优派专业电子书 让您回家旅途多姿
揭晓百万大奖三星bada魅力绽放中
大明龙权“江湖英雄会”全国PK大
永恒之塔校园达人挑战赛完美落幕
八卦图解 More>>
iPhone女孩微博爆红 最宝贵东西换 大连护士门大尺度艳照高清组图
中关村艳照门女主角详记录高清组 宫如敏不雅照疯传 看张馨予韩一菲