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

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

突然整理硬盘时找到了两年前写的一个网站,准备扔掉,但是还是把部分方法保留到博客吧!虽然现在对于自己已经用处不大,但是还是纪念一下!

生成验证码:


using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Drawing; 
 
public partial class CheckCode : System.Web.UI.Page 

    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!this.IsPostBack) 
        { 
            //生成验证码 
            string temp = this.GetCode(4); 
            HttpCookie cookie = new HttpCookie("yzm"); 
            cookie.Value = temp; 
            Response.Cookies.Add(cookie); 
            //画图 
            this.GetCheckCodeImage(temp); 
        } 
    } 
 
    //产生随机字符串  
    private string GetCode(int num) 
    { 
        string[] source ={ "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 code = ""; 

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

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

豫ICP备11007008号-1