ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:18KB ,
资源ID:22396314      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/22396314.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C#封装类NET MVC WEBFORMWord格式.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C#封装类NET MVC WEBFORMWord格式.docx

1、 v.SetRandomAngle = 4; /文字大小 v.SetFontSize = 15; /背景色 /v.SetBackgroundColor /前景噪点数量 /v.SetForeNoisePointCount = 3; /v.SetFontColor =Color.Red; /.还有更多设置不介绍了 var questionList = new Dictionary() 1+1=?,2,喜羊羊主角叫什么名字?喜羊羊 ,【我爱你】中间的那个字?爱 ; var questionItem = v.GetQuestion();/不赋值为随机验证码 例如: 1*2=? 这种 /指定验证文本 /

2、v.SetVerifyCodeText v.SetVerifyCodeText = questionItem.Key; SessionVerifyCode = questionItem.Value; /输出图片 v.OutputImage(System.Web.HttpContext.Current.Response); 2、前台设用action或者pageload页面地址,js给src更换url添加随机参数 达到刷新验证码的功能 3、完整封装类using System;using System.Collections.Generic;using System.Drawing;using Sy

3、stem.Drawing.Drawing2D;using System.Drawing.Imaging;using System.IO;using System.Linq;using System.Text;using System.Web;namespace Idea.Models / / 验证码类/summary public class VerifyCodeSugar private Random objRandom = new Random(); #region setting / /验证码长度 public int SetLength = 4; / 验证码字符串 public str

4、ing SetVerifyCodeText get; set; / 是否加入小写字母 public bool SetAddLowerLetter = false; / 是否加入大写字母 public bool SetAddUpperLetter = false; / 字体大小 public int SetFontSize = 18; / /字体颜色 public Color SetFontColor = Color.Blue; / 字体类型 public string SetFontFamily = Verdana; / 背景色 public Color SetBackgroundColor

5、= Color.AliceBlue; / 前景噪点数量 public int SetForeNoisePointCount = 2; / 随机码的旋转角度 public int SetRandomAngle = 40; / 是否随机字体颜色 public bool SetIsRandomColor = false; / 图片宽度 private int SetWith get return this.SetVerifyCodeText.Length * SetFontSize; / 图片高度 private int SetHeight return Convert.ToInt32(60.0 /

6、 100) * SetFontSize + SetFontSize); #endregion #region Constructor Method public VerifyCodeSugar() this.GetVerifyCodeText(); #region Private Method / 得到验证码字符串 private void GetVerifyCodeText() /没有外部输入验证码时随机生成 if (String.IsNullOrEmpty(this.SetVerifyCodeText) StringBuilder objStringBuilder = new String

7、Builder(); /加入数字1-9 for (int i = 1; i private void AddForeNoisePoint(Bitmap objBitmap) objBitmap.Width * this.SetForeNoisePointCount; objBitmap.SetPixel(objRandom.Next(objBitmap.Width), objRandom.Next(objBitmap.Height), this.SetFontColor); / 添加背景噪点objGraphics private void AddBackgroundNoisePoint(Bit

8、map objBitmap, Graphics objGraphics) using (Pen objPen = new Pen(Color.Azure, 0) objBitmap.Width * 2; objGraphics.DrawRectangle(objPen, objRandom.Next(objBitmap.Width), objRandom.Next(objBitmap.Height), 1, 1); / 获取随机颜色returns/returns private Color GetRandomColor() Random RandomNum_First = new Random

9、(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_G

10、reen 400) ? 0 : 400 - int_Red - int_Green; int_Blue = (int_Blue 255) ? 255 : int_Blue; return Color.FromArgb(int_Red, int_Green, int_Blue); #region Public Method / 输出验证码图片objHttpResponseHttp响应实例输出是否成功 public bool OutputImage(HttpResponse objHttpResponse) bool result = false; if (this.SetIsRandomColo

11、r) this.SetFontColor = GetRandomColor(); ; using (Bitmap objBitmap = this.GetVerifyCodeImage() if (objBitmap != null) using (MemoryStream objMS = new MemoryStream() objBitmap.Save(objMS, ImageFormat.Jpeg); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ContentType = image/

12、Jpeg HttpContext.Current.Response.BinaryWrite(objMS.ToArray(); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); result = true; / 获取问题questionList默认数字加减验证 public KeyValuePair GetQuestion(Dictionary questionList = null) if (questionList = null) questionList = new Dictionary();

13、 var operArray = new string +, *num var left = objRandom.Next(0, 10); var right = objRandom.Next(0, 10); var oper = operArrayobjRandom.Next(0, operArray.Length); if (oper = ) string key = string.Format(0+1=?, left, right); string val = (left + right).ToString(); questionList.Add(key, val); else if (oper = 01=? string val = (left * right).ToString(); else var num = objRandom.Next(1000, 9999); questionList.Add(num.ToString(), num.ToString(); return questionList.ToList()objRandom.Next(0, questionList.Count);

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1