Exemple #1
0
        public void VerificationCode()
        {
            //构造验证码图片
            Smart.Utility.ValidateCode validateCode = new Utility.ValidateCode();
            validateCode.Border      = true;
            validateCode.BorderColor = Color.Red;
            validateCode.BorderWidth = 1;
            validateCode.Chaos       = true;
            validateCode.Colors      = new Color[] { Color.Red, Color.Gray, Color.Blue, Color.Beige };
            validateCode.FontSize    = 13;
            validateCode.Length      = 4;
            validateCode.Padding     = 1;

            //生成随机数字
            Random rd       = new Random();
            string codeText = string.Format("{0}{1}{2}{3}",
                                            rd.Next(0, 9).ToString(),
                                            rd.Next(0, 9).ToString(),
                                            rd.Next(0, 9).ToString(),
                                            rd.Next(0, 9).ToString());

            //验证码文本加入Session
            this.Session["validatecode"] = codeText;

            //向客户端返回一张验证码图片
            Bitmap image = validateCode.CreateImageCode(codeText);

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            this.Response.ClearContent();
            this.Response.ContentType = "image/png";
            this.Response.BinaryWrite(ms.GetBuffer());
            ms.Close();
            ms = null;
            image.Dispose();
            image = null;
        }
        public void VerificationCode()
        {
            //构造验证码图片
            Smart.Utility.ValidateCode validateCode = new Utility.ValidateCode();
            validateCode.Border = true;
            validateCode.BorderColor = Color.Red;
            validateCode.BorderWidth = 1;
            validateCode.Chaos = true;
            validateCode.Colors = new Color[] { Color.Red, Color.Gray, Color.Blue, Color.Beige };
            validateCode.FontSize = 13;
            validateCode.Length = 4;
            validateCode.Padding = 1;

            //生成随机数字
            Random rd = new Random();
            string codeText = string.Format("{0}{1}{2}{3}",
                rd.Next(0, 9).ToString(),
                rd.Next(0, 9).ToString(),
                rd.Next(0, 9).ToString(),
                rd.Next(0, 9).ToString());

            //验证码文本加入Session
            this.Session["validatecode"] = codeText;

            //向客户端返回一张验证码图片
            Bitmap image = validateCode.CreateImageCode(codeText);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            this.Response.ClearContent();
            this.Response.ContentType = "image/png";
            this.Response.BinaryWrite(ms.GetBuffer());
            ms.Close();
            ms = null;
            image.Dispose();
            image = null;
        }