net驗證碼源碼
『壹』 .net簡訊驗證碼是如何實現的
首先你要有簡訊的介面,這個你只閉桐有想辦法從別的地方購買。
然後:
你先放一個文本框一個按鈕填寫手機號碼慶芹發送簡訊,然後搞一個臨時的庫保存下數據,保存手機號碼和隨機驗證碼、狀態,時間寫上5分鍾後的時間。這四個參數!
進入等等輸入頁面,5分鍾驗證碼過期,用過的修改狀態譽態畢,5分鍾後可以重發。
驗證碼就這樣操作,如果有什麼困難的地方可以HI網路我~~~
『貳』 c# .net 生成圖片驗證碼的代碼
說明:
.net 萬歲
.net framework 的類庫真是太強了, 用 GDI+ 可以干N多N多事情。
廣告時間:
shawl.qiu C# CMS 系統 預計40天後開始編碼, 現在逐步設計中, 免得到時求職說什麼什麼作品唉。
PS: 今天求職真是慘不忍睹虧亮正, 誰要招網鍵緩頁相關的請聯系 13435580019, 邱先生。
什麼地方俺都去, 工資只要能過活就行, 但是食宿問題得解決。
shawl.qiu
2007-02-01
class checkcode:
復制代碼 代碼如下:
%@ Page Language="C#" AutoEventWireup="True" %
%@ import Namespace="System.Drawing"%
%@ import Namespace="System.Drawing.Drawing2D"%
%@ import Namespace="System.Web"%
script runat="server"
private void Page_Load(object sender, System.EventArgs e)
{
String sRndStr=checkcode.rndStr(4);
checkcode.general(sRndStr);
}
/*-----------------------------------------------------------------------------------*
* shawl.qiu c# .net checkcode class v1.0
*-----------------------------------------------------------------------------------*/
//---------------------------------------------------------------------begin class checkcode
public class checkcode
{
//-----------------------------------begin event
public checkcode()
{
}
~checkcode()
{
}
//-----------------------------------end event
//-----------------------------------begin public constant
//-----------------------begin about
public const String auSubject="shawl.qiu c# .net checkcode class";
public const String auVersion="v1.0";
public const String au="shawl.qiu";
public const String auEmail="[email protected]";
public const String auBlog="";
public const String auCreateDate="2007-2-1";
//-----------------------end about
//-----------------------------------end public constant
//-----------------------------------begin public static method
public static void general(銷悔String sCc)
{
Int32 ccLen=sCc.Length;
String ccFtFm="Arial";
Int32 ccFtSz=12;
Int32 ccWidth=ccLen*ccFtSz+1;
Int32 ccHeight=ccFtSz+5;
using(Bitmap oImg = new Bitmap(ccWidth, ccHeight))
{
using(Graphics oGpc=Graphics.FromImage(oImg))
{
HatchBrush hBrush = new HatchBrush(HatchStyle.DashedVertical,
Color.Yellow, Color.Silver);
oGpc.FillRectangle(hBrush, 0, 0, ccWidth, ccWidth);
oGpc.DrawString(sCc,new System.Drawing.Font(ccFtFm,ccFtSz, FontStyle.Bold),
new System.Drawing.SolidBrush(Color.Black),0,0);
//-----------------------邊框
Pen blackPen = new Pen(Color.Black, 1);
oGpc.DrawLine(blackPen, 0, ccHeight, 0, 0); // 左豎線
oGpc.DrawLine(blackPen, 0,0,ccWidth,0); // 頂橫線
oGpc.DrawLine(blackPen, ccWidth-1,0,ccWidth-1,20); // 右豎線
oGpc.DrawLine(blackPen, 0, ccHeight-1, ccWidth, ccHeight-1); // 底橫線
writeImg(oImg);
}
}
} // end public static void general
public static String rndStr(Int32 len)
{
String sTemp="";
String sForRnd="0,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";
String[] aRnd=sForRnd.Split(',');
Random oRnd=new Random();
Int32 iArLen=aRnd.Length;
for(Int32 i=0; ilen; i++)
{
sTemp+=aRnd[oRnd.Next(0,iArLen)];
}
return sTemp;
} // end public static String rndStr
//-----------------------------------end public static method
//-----------------------------------begin private static method
private static void writeImg(Bitmap oImg)
{
using(System.IO.MemoryStream ms=new System.IO.MemoryStream())
{
oImg.Save(ms,System.Drawing.Imaging.ImageFormat.Png);
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType="image/Png";
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
}
} // end private static void writeImg
}
//---------------------------------------------------------------------end class checkcode
/script
『叄』 asp.Net的驗證碼代碼怎麼寫啊
主要代碼如下:
//
生成隨散輪鄭機數字字元串
public
string
GetRandomNumberString(int
int_NumberLength)
{
string
str_Number
=
string.Empty;
Random
theRandomNumber
=
new
Random();
for
(int
int_index
=
0;
int_index
<
int_NumberLength;
int_index++)
str_Number
+=
theRandomNumber.Next(10).ToString();
return
str_Number;
}
生成隨機顏色
public
Color
GetRandomColor()
{
Random
RandomNum_First
=
new
Random((int)DateTime.Now.Ticks);
//
對於C#的隨機數,沒什麼好桐穗說的
System.Threading.Thread.Sleep(RandomNum_First.Next(50));
Random
RandomNum_Sencond
=
new
Random((int)DateTime.Now.Ticks);
//
為了在白色背景上顯示,盡量生成深色
int
int_Red
=
RandomNum_First.Next(256);
int
int_Green
=
RandomNum_Sencond.Next(256);
int
int_Blue
=
(int_Red
+
int_Green
>
400)
?
0
:
400
-
int_Red
-
int_Green;
int_Blue
=
(int_Blue
>
255)
?
255
:
int_Blue;
return
Color.FromArgb(int_Red,
int_Green,
int_Blue);
}
根據驗證字元串生成最終圖象
public
void
CreateImage(string
str_ValidateCode)
{
int
int_ImageWidth
=
str_ValidateCode.Length
*
13;
Random
newRandom
=
new
Random();
//
圖高20px
Bitmap
theBitmap
=
new
Bitmap(int_ImageWidth,
20);
Graphics
theGraphics
=
Graphics.FromImage(theBitmap);
//
白色背景
theGraphics.Clear(Color.White);
//
灰色邊框
theGraphics.DrawRectangle(new
Pen(Color.LightGray,
1),
0,
0,
int_ImageWidth
-
1,
19);
//
10pt的字體
Font
theFont
=
new
Font("Arial",
10);
for
(int
int_index
=
0;
int_index
<
str_ValidateCode.Length;
int_index++)
{
string
str_char
=
str_ValidateCode.Substring(int_index,
1);
Brush
newBrush
=
new
SolidBrush(GetRandomColor());
Point
thePos
=
new
Point(int_index
*
13
+
1
+
newRandom.Next(3),
1
+
newRandom.Next(3));
theGraphics.DrawString(str_char,
theFont,
newBrush,
thePos);
}
//
將生成的圖片發回客戶沖頌端
MemoryStream
ms
=
new
MemoryStream();
theBitmap.Save(ms,
ImageFormat.Png);
Response.ClearContent();
//需要輸出圖象信息
要修改HTTP頭
Response.ContentType
=
"image/Png";
Response.BinaryWrite(ms.ToArray());
theGraphics.Dispose();
theBitmap.Dispose();
Response.End();
}
最後在Page_Load中調用以上代碼
private
void
Page_Load(object
sender,
System.EventArgs
e)
{
if(!IsPostBack)
{
//
4位數字的驗證碼
string
str_ValidateCode
=
GetRandomNumberString(4);
//
用於驗證的Session
Session["ValidateCode"]
=
str_ValidateCode;
CreateImage(str_ValidateCode);
}
}
使用的時候在頁面中加入一個Image,將圖片路徑改為ValidateCode.aspx的相對路徑即可
<img
src="ValidateCode.aspx"
/>在需要驗證的地方填入如下代碼:
if
(TextBox1.Text
==
Session["ValidateCode"].ToString())
{
TextBox1.Text
=
"正確!";
}
else
TextBox1.Text
=
"錯誤!";OK,基本搞定,總結一下:
『肆』 c#.net編寫一個驗證碼,點擊驗證碼圖片可以切換驗證碼,輸入正確或者錯誤的時候都有文字提示
兩個頁面:
1.ValidateCode用於生返簡成驗證圖片的
2.ValidateFormPage表單顯示的
ValidateCode.aspx文件不用寫代碼
ValidateCode.aspx.cs代碼如下:
using System;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
namespace WebFormDemo
{
    public partial class ValidateCode : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // 4位數字的驗證碼
                string str_ValidateCode = GetRandomNumberString(4);
                // 用於驗證的Session
                Session["ValidateCode"] = str_ValidateCode;
                CreateImage(str_ValidateCode);
            }
        }
        public string GetRandomNumberString(int int_NumberLength)
        {
            string str_Number = string.Empty;
            Random theRandomNumber = new Random();
            for (int int_index = 0; int_index < int_NumberLength; int_index++)
                str_Number += theRandomNumber.Next(10).ToString();
            return str_Number;
        }
        //生成隨機顏色
        public Color GetRandomColor()
        {
            Random RandomNum_First = new Random((int)DateTime.Now.Ticks);
            //前世鏈 對於C#的隨機數,沒什麼好說的
            System.Threading.Thread.Sleep(RandomNum_First.Next(50));
            Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks);
            // 為了在白色背景上顯示,盡量生成深色
            int int_Red = RandomNum_First.Next(256);
            int int_Green = RandomNum_Sencond.Next(256);
            int int_Blue = (int_Red + int_Green > 400) ? 0 : 400 - int_Red - int_Green;
            int_Blue = (int_Blue > 255) ? 255 : int_Blue;
            return Color.FromArgb(int_Red, int_Green, int_Blue);
        }
        //根據驗慧孫證字元串生成最終圖象
        public void CreateImage(string str_ValidateCode)
        {
            int int_ImageWidth = str_ValidateCode.Length * 13;
            Random newRandom = new Random();
            // 圖高20px
            Bitmap theBitmap = new Bitmap(int_ImageWidth, 20);
            Graphics theGraphics = Graphics.FromImage(theBitmap);
            // 白色背景
            theGraphics.Clear(Color.White);
            // 灰色邊框
            theGraphics.DrawRectangle(new Pen(Color.LightGray, 1), 0, 0, int_ImageWidth - 1, 19);
            // 10pt的字體
            Font theFont = new Font("Arial", 10);
            for (int int_index = 0; int_index < str_ValidateCode.Length; int_index++)
            {
                string str_char = str_ValidateCode.Substring(int_index, 1);
                Brush newBrush = new SolidBrush(GetRandomColor());
                Point thePos = new Point(int_index * 13 + 1 + newRandom.Next(3), 1 + newRandom.Next(3));
                theGraphics.DrawString(str_char, theFont, newBrush, thePos);
            }
            // 將生成的圖片發回客戶端
            MemoryStream ms = new MemoryStream();
            theBitmap.Save(ms, ImageFormat.Png);
            Response.ClearContent(); //需要輸出圖象信息 要修改HTTP頭 
            Response.ContentType = "image/Png";
            Response.BinaryWrite(ms.ToArray());
            theGraphics.Dispose();
            theBitmap.Dispose();
            Response.End();
        }
    }
}
----------------------------------------------------------------------------
ValidateFormPage.aspx文件代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ValidateFormPage.aspx.cs" Inherits="WebFormDemo.ValidateFormPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <img src="ValidateCode.aspx" /><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Label
            ID="Label1" runat="server"></asp:Label>
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="驗證" />
    </div>
    </form>
</body>
</html>
----------------------------------------------------------------------------
ValidateFormPage.aspx.cs文件代碼如下:
using System;
namespace WebFormDemo
{
    public partial class ValidateFormPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        //給按鈕加一個點擊事件
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text == Session["ValidateCode"].ToString())
            {
                Label1.Text = "正確!";
            }
            else
            {
                Label1.Text = "錯誤!";
            }
        }
    }
}
『伍』 asp.net刷新驗證碼
你這中寫法,似乎無法直接刷新
 <asp:TextBox ID="txtyzm" runat="server"></asp:TextBox><span class="right"><img src="Yzm.aspx"   alt="看不清楚,換一張?首首唯" style="cursor: pointer;" onclick="this.src=this.src+'?'" /></span>
這樣的寫,是肯定能刷新的芹派
若還有問題也可以私信我哦~
如果滿意請【採納】【贊同】~
最後希望你能夠及時採納,謝謝~
即使不採納也請贊同下哈~
鼓勵下咱,讓咱有繼續回答問題的動力哈者培~
『陸』 net mvc 驗證碼怎麼實現
首先你要寫一個驗證碼的Controller,這里我給你粘一個:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Drawing;
usingSystem.Drawing.Imaging;
usingSystem.IO;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Mvc;
namespaceDemo.Controllers
{
publicclassValidateController:Controller
{
publicFileResultConfirmCode()
{
//生成4位隨機數消纖,並將其轉為string型,傳入session,4位數字由隨機數從1000-9999中提取。
stringConfirmCode=string.Empty;
Random兆槐rand=newRandom();
ConfirmCode=rand.Next(1000,9999).ToString();
Session["QuickChannelConfirmCode"]=ConfirmCode;
Randomrand1=newRandom();
Randomrand2=newRandom();
intred=rand1.Next(50);
intgreen=rand2.Next(100);
intblue1=(red+green>400)?0:400-red-green;
intblue2=(blue1>255)?255:blue1;
Colorcol=Color.FromArgb(red,green,blue2);
//intimageWidth=ConfirmCode.Length*13;
Bitmapbmp=newBitmap(135,44);
Graphicsg=Graphics.FromImage(bmp);
g.Clear(Color.LightGray);
g.DrawRectangle(newPen(Color.LightGray,1),0,0,134,43);
Fontfont=newFont("Harrington",30);
Brushbrush=newSolidBrush(col);//col為上文隨機出的顏色
Pointpo=newPoint(15,0);
g.DrawString(ConfirmCode,font,brush,po);
Response.ContentType="image/jpeg";
MemoryStreamms=new族橋友MemoryStream();
bmp.Save(ms,ImageFormat.Jpeg);
ms.Seek(0,SeekOrigin.Begin);
returnnewFileStreamResult(ms,"image/jpeg");
}
publicActionResultCheckCode(stringid)
{
//stringquickChannalConfirmCode=Request.QueryString["id"].ToString();
stringquickChannalConfirmCode=id.ToUpper();
if(Session["QuickChannelConfirmCode"]==null||"".Equals(Session["QuickChannelConfirmCode"].ToString()))
{
returnJson(false,JsonRequestBehavior.AllowGet);
}
stringyanzheng=Session["QuickChannelConfirmCode"].ToString();
Session.Remove("QuickChannelConfirmCode");
if(quickChannalConfirmCode==yanzheng)
{
returnJson(true,JsonRequestBehavior.AllowGet);
}
else
{
returnJson(false,JsonRequestBehavior.AllowGet);
}
}
}
}
在頁面上這樣調用:
<imgid="VerificationCodeImg"src="/Validate/ConfirmCode2"alt="驗證碼"/>
然後還要在頁面加上驗證:
<scripttype="text/javascript">
functionRefreshConfirmCode(){
varrad_num=parseInt(1000*Math.random());
$("#VerificationCodeImg").attr("src","/Validate/ConfirmCode/"+rad_num);
$("#YanZhengMa").val("");
}
$(function(){
$("#VerificationCodeImg").click(RefreshConfirmCode);
$("#LoginButton").click(function(event){
varthisForm=$("form").first();
if(thisForm.valid()){
varthisVerificationCode=$("#YanZhengMa").val();
if(thisVerificationCode){
$.getJSON('/Validate/CheckCode',{id:thisVerificationCode},function(json,textStatus){
if(!json){
RefreshConfirmCode();
thisForm.valid();
}
else{
thisForm.submit();
}
});
}
}
returnfalse;
});
});
</script>
『柒』 asp.net驗證碼
添加一個checkcode.aspx文件,在cs中寫入:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
namespace EIMS
{
    public partial class CheckCode : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CreateCheckCodeImage(GenerateCheckCode());
        }
        private string GenerateCheckCode()            //繪制4個隨機蔽汪盯數或字母
        {
            int number;
            char code;
            string checkCode = String.Empty;
            Random random = new Random();
            for (int i = 0; i < 4; i++)
            {
                number = random.Next();
                if (number % 2 == 0)
                    code = (char)('0' + (char)(number % 10));
                else
                    code = (char)('A' + (char)(number % 26));
                checkCode += code.ToString();
            }
            Response.Cookies.Add(new HttpCookie("CheckCode", checkCode));
            return checkCode;
        }
        private void CreateCheckCodeImage(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)), 22);
            Graphics g = Graphics.FromImage(image);
            try
            {
                /陵扮/生成隨機生成器
                Random random = new Random();
                //清空圖片宏和背景色
                g.Clear(Color.White);
                //畫圖片的背景噪音線
                for (int i = 0; i < 2; 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.Black), x1, y1, x2, y2);
                }
                Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold));
                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
                g.DrawString(checkCode, font, brush, 2, 2);
                //畫圖片的前景噪音點
                for (int i = 0; i < 100; i++)
                {
                    int x = random.Next(image.Width);
                    int y = random.Next(image.Height);
                    image.SetPixel(x, y, Color.FromArgb(random.Next()));
                }
                //畫圖片的邊框線
                g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                Response.ClearContent();
                Response.ContentType = "image/Gif";
                Response.BinaryWrite(ms.ToArray());
            }
            finally
            {
                g.Dispose();
                image.Dispose();
            }
        }
    }
}
再在要添加驗證碼處添加<asp:Image ID="Image1" runat="server" Height="27px" Width="77px" 
                                    imageurl="CheckCode.aspx"/>
即可 
--------------------------------------------------------------------
Dreamweaver我很少用,不太了解,你在網上找一下解決方案吧
『捌』 asp.net做登陸頁面的驗證碼怎麼寫,求具體的操作和代碼
網上找個驗證碼,基本上都是個aspx+aspx.cs這樣,放個<img>標簽,src為驗證碼地址,判斷驗證碼用ajax,一般驗證碼都放session,判斷下就可以,找不到我放個驗證碼給你
『玖』 asp.net(C#)圖片隨機驗證碼的代碼!不要在網上抄的!要自己測試成功的!
首先,新建文件:閉耐擾CreateImage.aspx
裡面不用寫代碼,
CreateImage.aspx.cs 如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CreateImage
{
 /// <summary>
 /// CreateImage 的摘要說明。
 /// </轎旦summary>
 public class CreateImage : System.Web.UI.Page
 {
  protected void Page_Load(object sender, EventArgs e)
  {
   string checkCode = CreateCode(4);
   
   //用於驗證
   Session["CheckCode"] = checkCode;
   CreateImages(checkCode);
  }
  /*產畝陸生驗證碼*/
  public string CreateCode(int codeLength)
  {
        
   string so = "1,2,3,4,5,6,7,8,9,0,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[] strArr=so.Split(',');
   string code = "";
   Random rand=new Random();
   for (int i = 0; i < codeLength; i++)
   {
    code+=strArr[rand.Next(0, strArr.Length)];
   }
   return code;
  }
  /*產生驗證圖片*/
  public void CreateImages(string code)
  {
        
   Bitmap image = new Bitmap(60, 20);
   Graphics g = Graphics.FromImage(image);
   WebColorConverter ww=new WebColorConverter();
   g.Clear((Color)ww.ConvertFromString("#FAE264"));
   Random random = new Random();
   //畫圖片的背景噪音線
   for (int i = 0; i < 12; 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.LightGray), x1, y1, x2, y2);
   }
   Font font = new Font("Arial", 15, FontStyle.Bold | FontStyle.Italic);
   System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(
    new Rectangle(0,0,image.Width,image.Height),Color.Blue,Color.Gray,1.2f,true);
   g.DrawString(code, font, brush, 0, 0);
   //畫圖片的前景噪音點
   for (int i = 0; i < 10; i++)
   {
       int x = random.Next(image.Width);
       int y = random.Next(image.Height);
       image.SetPixel(x, y, Color.White);
   }
   //畫圖片的邊框線
   g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
   System.IO.MemoryStream ms = new System.IO.MemoryStream();
   image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
   Response.ClearContent();
   Response.ContentType = "image/Gif";
   Response.BinaryWrite(ms.ToArray());
   g.Dispose();
   image.Dispose();
  }
   
  #region Web 窗體設計器生成的代碼
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內容。
  /// </summary>
  private void InitializeComponent()
  {    
   this.Load += new System.EventHandler(this.Page_Load);
  }
  #endregion
 }
}
之後只需要在調用的時候 填入<img src="CreateImage.aspx" align="middle">就可以
例如:新建WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CreateImage.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
<html>
  <head>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  </head>
  <body MS_POSITIONING="GridLayout">
 
    <form id="Form1" method="post" runat="server">
  <img src="CreateImage.aspx" align="middle"><BR>
     </form>
 
  </body>
</html>
『拾』 net用戶名密碼驗證碼
Session["Valid"滑喊] = my51aspx;
        //以下三句,通過隨機找一個現有圖象產生一個畫布Bitmap
        string bgFilePath = Server.MapPath(".\\images\\bg" + new Random().Next(5) + ".jpg");//模讓嫌隨機找個圖象
        System.Drawing.Image imgObj = System.Drawing.Image.FromFile(bgFilePath);
        Bitmap newBitmap = new Bitmap(imgObj, 290, 80);//建立點陣圖對象
        Graphics g = Graphics.FromImage(newBitmap);//根據上面創建的點陣圖對象創建繪圖面
        SolidBrush brush = new SolidBrush(Color.Black);//設置畫筆顏色
        //定義一個含10種字體的數組
        String[] fontFamily ={ "Arial", "Verdana", "Comic Sans MS", "Impact", "Haettenschweiler", "Lucida Sans Unicode", "Garamond", "Courier New", "Book Antiqua", "Arial Narrow" };
        /旦手/通過循環,繪制每個字元,
        for (int a = 0; a < my51aspx.Length; a++)
        {
            Font textFont = new Font(fontFamily[rd.Next(9)], 30, FontStyle.Bold);//字體隨機,字型大小大小30,加粗 
            //每次循環繪制一個字元,設置字體格式,畫筆顏色,字元相對畫布的X坐標,字元相對畫布的Y坐標
            g.DrawString(my51aspx.Substring(a, 1), textFont, brush, 40 + a * 36, 20);
        }
        //保存畫的圖片到輸出流中
        newBitmap.Save(Response.OutputStream, ImageFormat.Gif);
    }
        }
    }
