在做一个登录页时,我们通常需要设置验证码,防止非法人员通过其他手段非法登录。在做一个页面的验证码时,我们需要先建立一个Active的Web页面,来随机的产生数字和字母,同时把产生的数字存储在Session中,传递给登录页,用来验证。并且定义一个画板,在Active页面绘出验证码的背景颜色,在Active页面的代码如下:
protected void Page_Load(object sender, EventArgs e){//显示验证码this.GenImg(this.GenCode(4));Session["image"] = this.GenCode(4);Server.Transfer("Default.aspx");//Console.WriteLine(this.GenCode(4));}private string GenCode(int num){string [] source={"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","