//定义方法

public partial class VerificationCode : System.Web.UI.Page
    {
        string ImagePath = "images/validator.jpg";
        string sValidator = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            validate();
        }
        public void validate()
        {
            if (Request.Params["Validator"] != null)
            {
                sValidator = Request.Params["Validator"].ToString();
            }

///创建Bmp位图

Bitmap bitMapImage = new Bitmap(Server.MapPath(ImagePath));
            Graphics graphicImage = Graphics.FromImage(bitMapImage);

///设置画笔的输出模式
            graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
            ///添加文本字符串
            graphicImage.DrawString(sValidator, new Font("Arial", 20, FontStyle.Bold), SystemBrushes.WindowText, new Point(0, 0));

///设置图像输出的格式
            Response.ContentType = "image/jpeg";

///保存数据流
            bitMapImage.Save(Response.OutputStream, ImageFormat.Jpeg);

///释放占用的资源
            graphicImage.Dispose();
            bitMapImage.Dispose();
        }
    }

---------------------------------------------------------------------------------------------------------------------------------------------------------

//调用

public partial class login : System.Web.UI.Page
    {

static string sValidator = "";
        private readonly string sValidatorImageUrl = "VerificationCode.aspx?Validator=";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

sValidator = GetRandomint();
                ValidateImage.ImageUrl = sValidatorImageUrl + sValidator;

}
        }

private String GetRandomint()
        {
            Random random = new Random();
            return (random.Next(100000, 999999).ToString());
        }

aspx生成验证码的更多相关文章

  1. ASP.NET ashx实现无刷新页面生成验证码

    现在大部分网站登陆时都会要求输入验证码,在网上也看了一些范例,现在总结一下如何实现无刷新页面生成验证码. 效果图: 实现方式: 前台: <div> <span>Identify ...

  2. 【转载】ASP.NET 生成验证码

    直接上code using System; using System.Collections.Generic; using System.Linq; using System.Web; using S ...

  3. 动态生成验证码———MVC版

    上面有篇博客也是写的验证码,但那个是适用于asp.net网站的. 今天想在MVC中实现验证码功能,弄了好久,最后还是看博友文章解决的,感谢那位博友. 首先引入生成验证码帮助类. ValidateCod ...

  4. laravel 生成验证码的方法

    在Laravel中有很多图片验证码的库可以使用,本篇介绍其中之一:gregwar/captcha,这个库比较简单,在Laravel中比较常用.下面我们就来介绍下使用细节: 首先, composer.j ...

  5. java web学习总结(九) -------------------通过Servlet生成验证码图片

    一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:

  6. android 生成验证码图片

    (转自:http://blog.csdn.net/onlyonecoder/article/details/8231373) package com.nobeg.util; import java.u ...

  7. PHP 动态生成验证码

    ……机器人会在网站中搜寻允许他们插入广告的输入表单,在虚拟世界没有什么能阻挡它们胡作非为.这些机器人效率极高,完全不关心所攻击的表单的本来用途.它们唯一的目标就是用它们的垃圾广告覆盖你的内容,残忍地为 ...

  8. PHP生成验证码及单实例应用

    /* note: * this 指向当前对象本身 * self 指向当前类 * parent 指向父类 */ /* 验证码工具类 * @author pandancode * @date 20150- ...

  9. PHP-仿ecshop生成验证码

    <?php /* 生成验证码 */ // 1.创建画布(基于已有图像) $n = mt_rand(1,5); $im = imagecreatefromjpeg('./images/captch ...

随机推荐

  1. Linux操作系统分析__破解操作系统的奥秘

    学号:SA12226343  姓名:sunhongbo 一.操作系统工作的基础 存储程序计算机和堆栈(函数调用堆栈)机制以及中断机制是操作系统工作的基础. 现代计算机仍采用存储程序计算机的结构体系和工 ...

  2. 重新认识Intent

    相信android开发工程师,对Intent一定不陌生,在整个开发中随时都用到了,今天我们总结一下Intent. 1. 为什么需要Intent? 在android Intent机制是协助应用间的交互与 ...

  3. cocos2dx 帧动画(iOS)

    植物大战僵尸的植物摇摆效果 //帧动画 Animation *animation = Animation::create(); Sprite *sprite = Sprite::create(&quo ...

  4. javascript版QQ在线聊天挂件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. C语言初学 判断闰年的问题

    #include<stdio.h> main( ) {  int   year , leap; scanf("%d",&year);             i ...

  6. HBase笔记--安装及启动过程中的问题

    1.使用hbase shell的时候运行命令执行失败 例如:在shell下执行 status,失败. 可能的原因:节点之间的时间差距过大 解决方法调整两个节点的时间,使二者一致,这里用了个比较笨的方法 ...

  7. 关于css中overflow的一些理解

    在做移动端开发的时候,遇到过这么个问题:要把图片进行放大,但有时候图片比较长,一个手机的版面看不了,于是需要用到overflow的属性,刚开始用了overflow-y:scroll, 于是问题来了,如 ...

  8. z-index 所遇问题

    document.getElementById('wx_share_img').style.cssText = "width:100%;height:100%;position:fixed; ...

  9. Matlab基本数据类型

    本文转载自:http://hi.baidu.com/xmf6227/blog/item/97ca2ddf98f1b61f495403cb.html Matlab中有15种基本数据类型,主要是整型.浮点 ...

  10. 再转一篇gtest1.6安装

    http://www.cppblog.com/izualzhy/archive/2012/07/31/185772.html googletest是一个用来写C++单元测试的框架,它是跨平台的,可应用 ...