asp.Net 一些常用的方法和类(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-17 14:40 点击:次
Random rd = new Random();
for (int i = 0; i < num; i++)
{
code += source[rd.Next(0, source.Length)];
}
Session["ValidateCode"] = code;//将字符串保存到Session中,以便需要时进行验证
return code;
}
#region 验证码
/// <summary>
/// 生成验证码
/// </summary>
/// <param name="checkCode"></param>
private void GetCheckCodeImage(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)),25);
Graphics g = Graphics.FromImage(image);
try
{
Random random = new Random(); //生成随机生成器
g.Clear(Color.White); //清空图片背景色 www.2cto.com
for (int i = 0; i < 5; 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.Silver), x1, y1, x2, y2);
}
Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- ASP.net页面中请求远程Web站点
- Request.Cookies 和 Response.Cookies 的区别
- ASP.NET之Gridview图解(1)
- 步步为营 SharePoint 开发学习笔记系列&nb
- 用OpenXml在文档的尾部添加一个Rich Text Content Con
- ASP.NET FormsAuthentication跨站点登录时绝对地址返
- 使用ASP.NET MVC3+EF+Jquery制作文字直播系统(一
- 向Excel文档中嵌入VBA控件和UserForm并显示
- ASP.NET生成高质量缩略图通用函数(c#代码)
- Spring.Net学习系列一: 统一异常处理



