亚洲天堂一级片-亚洲天堂三区-亚洲天堂久久精品成人-亚洲天堂毛片-久久国产欧美日韩高清专区-久久国产欧美日韩精品免费

北京北大青鳥校區學術老師指導:ASP.NET驗證碼

此技術文章由北京北大青鳥校區學術部丁老師提供:
1.創建“一般處理程序”(北京北大青鳥校區
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
///
/// ChkCode 的摘要說明
///
public class ChkCode : IHttpHandler
{
//驗證碼的字符集
private readonly char[] character = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
public void ProcessRequest(HttpContext context)
{
string chkCode = string.Empty;
//顏色列表,用于驗證碼、噪線、噪點
Color[] color = { Color.Black, Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Brown, Color.Brown, Color.DarkBlue };
//字體列表,用于驗證碼
string[] font = { "Times New Roman", "MS Mincho", "Book Antiqua", "Gungsuh", "PMingLiU", "Impact" };
Random rnd = new Random();
//生成驗證碼字符串
for (int i = 0; i < 4; i++)
{
chkCode += character[rnd.Next(character.Length)];
}
//將驗證碼寫入Session
context.Session["ChkCode"] = chkCode;
Bitmap bmp = new Bitmap(100, 40);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
//畫噪線
for (int i = 0; i < 10; i++)
{
int x1 = rnd.Next(100);
int y1 = rnd.Next(40);
int x2 = rnd.Next(100);
int y2 = rnd.Next(40);
Color clr = color[rnd.Next(color.Length)];
g.DrawLine(new Pen(clr), x1, y1, x2, y2);
}
//畫驗證碼字符串 (北京北大青鳥校區
for (int i = 0; i < chkCode.Length; i++)
{
string fnt = font[rnd.Next(font.Length)];
Font ft = new Font(fnt, 18);
Color clr = color[rnd.Next(color.Length)];
g.DrawString(chkCode[i].ToString(), ft, new SolidBrush(clr), (float)i * 20 + 8, (float)8);
}
//畫噪點
for (int i = 0; i < 100; i++)
{
int x = rnd.Next(bmp.Width);
int y = rnd.Next(bmp.Height);
Color clr = color[rnd.Next(color.Length)];
bmp.SetPixel(x, y, clr);
}
//清除該頁輸出緩存,設置該頁無緩存
context.Response.Buffer = true;
context.Response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0);
context.Response.Expires = 0;
context.Response.CacheControl = "no-cache";
context.Response.AppendHeader("Pragma", "No-Cache");
//將驗證碼圖片寫入內存流,并將其以 "image/Png" 格式輸出
MemoryStream ms = new MemoryStream();
try
{
bmp.Save(ms, ImageFormat.Png);
context.Response.ClearContent();
context.Response.ContentType = "image/Png";
context.Response.BinaryWrite(ms.ToArray());
}
finally
{
//顯式釋放資源
bmp.Dispose();
g.Dispose();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}(北京北大青鳥校區

2.創建測試頁


(北京北大青鳥校區
北大青鳥網上報名
北大青鳥招生簡章
主站蜘蛛池模板: 亚洲欧美精品中字久久99 | 国产第九页 | 国产性自爱拍偷在在线播放 | 亚洲欧美日韩色 | 免费观看一级特黄欧美大片 | 亚洲在线影院 | 亚洲午夜成激人情在线影院 | 特黄特a级特别特级特毛片 特黄特黄 | 欧美日韩国产高清一区二区三区 | 欧美毛片在线观看 | 狼人青草久久网尹人 | 欧美精品1 | 亚洲综合亚洲 | 国产精品欧美视频另类专区 | 毛片在线不卡 | 成人国产片免费 | 日韩中文字幕精品一区在线 | 国产精彩视频在线 | aa级毛片毛片免费观看久 | 色一伦一情一区二区三区 | 国产成人一区二区视频在线观看 | 久久精品视频9 | a级国产乱理伦片在线 | 99久久精品无码一区二区毛片 | free性丰满白嫩白嫩的hd | 日韩欧美在线一级一中文字暮 | 国产免费久久精品 | 精品在线视频播放 | 久草手机视频在线 | 国产成人手机视频 | 久草热线视频 | 国产一区二区三区免费在线视频 | 成人精品免费视频 | 日本三级特黄 | 欧美激情伦妇在线观看 | 中文精品视频一区二区在线观看 | 国产精品拍拍拍福利在线观看 | 三级黄a | 久久久久久a亚洲欧洲aⅴ | 日韩美毛片 | 亚洲欧美日韩国产综合高清 |