国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net 驗證碼生成和刷新及驗證

2024-07-10 12:38:31
字體:
來源:轉載
供稿:網友
驗證碼技術是為了防止暴力破解等而設定的。現在一般的網站注冊等都提供驗證碼功能,特別是騰訊更是長長的一串。文中參考了別人的代碼。有了就沒有必要再寫了。可以讀一下。不過我測試時發現了兩次PageLoad的問題。注釋了兩句即可。同時修改了namespaces。同時提供完整的驗證說明:
1 新建VerifyCode.aspx
cs文件代碼如下:
代碼如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
/**///// <summary>
/// 頁面驗證碼程序
/// 使用:在頁面中加入HTML代碼 <img src="VerifyCode.aspx">
/// </summary>
public partial class VerifyCode : System.Web.UI.Page
...{
static string[] FontItems = new string[] ...{ "Arial",
"Helvetica",
"Geneva",
"sans-serif",
"Verdana"
};
static Brush[] BrushItems = new Brush[] ...{ Brushes.OliveDrab,
Brushes.ForestGreen,
Brushes.DarkCyan,
Brushes.LightSlateGray,
Brushes.RoyalBlue,
Brushes.SlateBlue,
Brushes.DarkViolet,
Brushes.MediumVioletRed,
Brushes.IndianRed,
Brushes.Firebrick,
Brushes.Chocolate,
Brushes.Peru,
Brushes.Goldenrod
};
static string[] BrushName = new string[] ...{ "OliveDrab",
"ForestGreen",
"DarkCyan",
"LightSlateGray",
"RoyalBlue",
"SlateBlue",
"DarkViolet",
"MediumVioletRed",
"IndianRed",
"Firebrick",
"Chocolate",
"Peru",
"Goldenrod"
};
private static Color BackColor = Color.White;
private static Pen BorderColor = Pens.DarkGray;
private static int Width = 52;
private static int Height = 21;
private Random _random;
private string _code;
private int _brushNameIndex;
override protected void OnInit(EventArgs e)
...{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
//InitializeComponent();
//base.OnInit(e);
}
/**//**//**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
...{
//this.Load += new System.EventHandler(this.Page_Load);
}
/**//// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Page_Load(object sender, System.EventArgs e)
...{
if (!IsPostBack)
...{
//
// TODO : initialize
//
this._random = new Random();
this._code = GetRandomCode();
//
// TODO : use Session["code"] save the VerifyCode
//
Session["code"] = this._code;
//
// TODO : output Image
//
this.SetPageNoCache();
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 达州市| 肥乡县| 贵德县| 涡阳县| 福州市| 花垣县| 汤原县| 桃园县| 荥阳市| 天全县| 贡觉县| 当涂县| 乐昌市| 余姚市| 通化县| 灵璧县| 临颍县| 焦作市| 长乐市| 锡林郭勒盟| 合水县| 贵阳市| 灵石县| 平罗县| 抚松县| 浏阳市| 游戏| 沂水县| 井陉县| 理塘县| 怀来县| 会昌县| 开江县| 海南省| 沙坪坝区| 扬中市| 邢台市| 金华市| 遂川县| 通海县| 鞍山市|