在网上找的一个图片验证码,单独放在一个aspx页面中,能显示一个图片验证码,现在我想放到页面中的一个
<asp:Image ID="imgVali" runat="server"  />中,不知道怎么搞aspx页面中cs源码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.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
public partial class test : System.Web.UI.Page
{    protected void Page_Load(object sender, EventArgs e)
    {
        this.CreateCheckCodeImage(CreateCheckCodeString());//加载 在前台页面显示    }    private string CreateCheckCodeString()
    {
        char[] allCharArry ={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','L','L','M','N','O','P','Q','R','S','T','U',
'W','X','Y','Z'};        string randomCode = "";//验证码字符串
        Random rand = new Random();
        for (int i = 0; i < 4; i++)//生成4位
            randomCode += allCharArry[rand.Next(allCharArry.Length)];
        return randomCode;
    }
    public void CreateCheckCodeImage(string sFilePath)
    {
        int iWidth = 55;//定义图片宽度
        int iHeight = 22;//定义图片高度
        Font font = new Font("Arial", 12, FontStyle.Bold);
        SolidBrush brush = new SolidBrush(Color.Black);
        Pen pen1 = new Pen(Color.Gray, 0);
        Pen pen2 = new Pen(Color.FromArgb(255, 100, 00, 100), 0);
        Bitmap image = new Bitmap(iWidth, iHeight);
        Graphics g = Graphics.FromImage(image);
        g.Clear(ColorTranslator.FromHtml("#F0F0F0"));
        RectangleF rect = new RectangleF(5, 2, iWidth, iHeight);
        Random rand = new Random();
        for (int i = 0; i < 2; i++)//生成2条横线
        {
            Point p1 = new Point(0, rand.Next(iHeight));
            Point p2 = new Point(iWidth, rand.Next(iHeight));
            g.DrawLine(pen1, p1, p2);
        }
        for (int i = 0; i < 4; i++)//生成4条竖线干扰线
        {
            Point p1 = new Point(rand.Next(iWidth), 0);
            Point p2 = new Point(rand.Next(iWidth), iHeight);
            g.DrawLine(pen2, p1, p2);        }
        g.DrawString(CreateCheckCodeString(), font, brush, rect);        MemoryStream ms = new MemoryStream();
        image.Save(ms, ImageFormat.Gif);//保存图片
        Response.ClearContent();
        Response.ContentType = "image/Gif";
        Response.BinaryWrite(ms.ToArray());        g.Dispose();//释放对象
        image.Dispose();
    }}