【asp源码栏目提醒】:网学会员在asp源码频道为大家收集整理了“ASP.NET中的无刷新验证码的开发(完整代码) - 编程语言“提供大家参考,希望对大家有所帮助!
验证码:看不清using Systemusing System.Collections.Genericusing System.Linqusing System.Webusing System.Web.UIusing System.Web.UI.WebControlspublic partial class Login : System.Web.UI.Pageprotected void Page_Loadobject sender EventArgs eif Page.IsPostBackImage1.ImageUrl VerifyCode.aspxprotected void btnSubmit_Clickobject sender EventArgs eif SessionValidateCode nullstring outputValidateCode SessionValidateCode as stringstring inputValidateCode txtValidateCode.Text.Trimif string.CompareoutputValidateCode inputValidateCode true 0//Response.Write litErrorMsg.Text 输入的验证码错误!else//Response.Write litErrorMsg.Text 输入的验证码正确!region 调用下面的
方法实现
客户端保存 Cookie 验证模式private void ValidateMethodif Request.CookiesCheckCode nulllitErrorMsg.Text 您的浏览
器设置已被禁用 Cookies, 您
必须设置
浏览器允许使用 Cookies选项后才能使用本
系统。
litErrorMsg.Visible truereturnif String.CompareRequest.CookiesCheckCode.Value TextBox1.Text.ToString.Trimtrue 0litErrorMsg.Text 对不起,验证码
错误!litErrorMsg.Visible truereturnelselitErrorMsg.Text 恭喜,验证码输入
正确!litErrorMsg.Visible trueendregion//VerifyCode.aspx 为默认生成的代码using Systemusing System.Datausing System.Configurationusing System.Collectionsusing System.Webusing System.Web.Securityusing System.Web.UIusing System.Web.UI.WebControls.WebPartsusing System.Web.UI.HtmlControlsusing System.Drawingusing System.Drawing.Imagingusing System.Drawing.Drawing2Dusing System.IOpublic partial class VerifyCode : System.Web.UI.Pageprotected void Page_Loadobject sender EventArgs e//GenerateValidateCodeGenerateVerifyImage4//GenerateVerifyImageint lengthregion 【无刷新仿
google 波形扭曲彩色】验证码样式 0___GenerateValidateCodeprivate void GenerateValidateCodethis.Length this.lengththis.FontSize this.fontSizethis.Chaos this.chaosthis.BackgroundColor this.backgroundColorthis.ChaosColor this.chaosColorthis.CodeSerial this.codeSerialthis.Colors this.colorsthis.Fonts this.fontsthis.Padding this.paddingstring VNum this.CreateVerifyCode //取随机码SessionValidateCode VNum.ToUpper//取得验证码,以便后来验证this.CreateImageOnPageVNum this.Context // 输出图片//Cookie
验证模式, 使用 Cookies 取验证码的值//Response.Cookies.Addnew HttpCookieCheckCode code.ToUpperendregionregion 验证码长度默认 4 个验证码的长度int length 4public int Lengthget return length set length value endregionregion 验证码字体大小为了
显示扭曲效果,默认 40 像素,可以自行
修改int fontSize 22public int FontSizeget return fontSize set fontSize value endregionregion 边框补默认 1 像素int padding 2public int Paddingget return padding set padding value endregionregion
是否输出燥点默认不输出bool chaos truepublic bool Chaosget return chaos set chaos value endregionregion 输出燥点的颜色默认灰色Color chaosColor Color.LightGraypublic Color ChaosColorget return chaosColor set chaosColor value endregionregion 自定义背景色默认白色Color backgroundColor Color.Whitepublic Color BackgroundColorget return backgroundColor set backgroundColor value endregionregion 自定义随机颜色数组Color colors Color.Black Color.Red Color.DarkBlue Color.Green Color.Orange