asp.Net 一些常用的方法和类(2)

来源:未知 责任编辑:责任编辑 发表时间:2013-11-17 14:40 点击:

        Random rd = new Random(); 
        for (int i = 0; i < num; i++) 
        { 
            code += source[rd.Next(0, source.Length)]; 
        } 
        Session["ValidateCode"] = code;//将字符串保存到Session中,以便需要时进行验证   
        return code; 
 
    } 
 
 
    #region    验证码 
 
    /// <summary> 
    /// 生成验证码 
    /// </summary> 
    /// <param name="checkCode"></param> 
    private void GetCheckCodeImage(string checkCode) 
    { 
        if (checkCode == null || checkCode.Trim() == String.Empty) return; 
 
        System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)),25); 
        Graphics g = Graphics.FromImage(image); 
        try 
        { 
            Random random = new Random();     //生成随机生成器  
            g.Clear(Color.White);            //清空图片背景色 www.2cto.com
            for (int i = 0; i < 5; i++)     //画图片的背景噪音线 
            { 
                int x1 = random.Next(image.Width); 
                int x2 = random.Next(image.Width); 
                int y1 = random.Next(image.Height); 
                int y2 = random.Next(image.Height); 
                g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); 
            } 
            Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic)); 
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • 浅析.NET下XML数据访问新机制
  • asp.net 面试+笔试题目第1/2页
  • C# 邮件地址是否合法的验证
  • asp.net 设置GridView的选中行的实现代码
  • C#高级编程:数据库连接[1]
  • 经典C++程序1
  • IIS 自动回收导致后台定时器失效的问题解决
  • ASP.NET&#160;GridView列表代码示例
  • Asp.net MVC源码分析--Action Filter的链式调用
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1