易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.Net生成验证码

using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
public partial class images_code : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string chkCode = string.Empty;
//颜色列表,用于验证码、噪线、噪点
Color[] color ={ Color.Black, Color.Red, Color.Blue, Color.Green, Color.Orange,Color.Brown, Color.DarkBlue };
//字体列表,用于验证码
string[] font ={ "Times New Roman", "MS Mincho", "Book Antiqua", "Gungsuh","PMingLiU", "Impact" };
//验证码的字符集,去掉了一些容易混淆的字符
char[] character ={ '2', '3', '4', '5', '6', '8', '9', 'A', 'B', 'C', 'D', 'E','F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'Y' };
Random rnd = new Random();
//生成验证码字符串
for (int i = 0; i < 4; i++)
{
chkCode += character[rnd.Next(character.Length)];
}
//保存验证码的Cookie
HttpCookie anycookie = new HttpCookie("validateCookie");
anycookie.Values.Add("ChkCode", chkCode);
HttpContext.Current.Response.Cookies["validateCookie"].Values["ChkCode"] = chkCode;
Bitmap bmp = new Bitmap(80,20);
Graphics g = Graphics.fromImage(bmp);
g.Clear(Color.White);
//画噪线
for (int i = 0; i < 3; i++)
{
int x1 = rnd.Next(80);
int y1 = rnd.Next(20);
int x2 = rnd.Next(80);
int y2 = rnd.Next(20);
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, 11);
Color clr = color[rnd.Next(color.Length)];
g.DrawString(chkCode.ToString(), ft, new SolidBrush(clr), (float)i * 20 + 6, (float)2);
}
//画噪点
for (int i = 0; i < 50; 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);
}
//清除该页输出缓存,设置该页无缓存
Response.Buffer = true;
Response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0);
Response.Expires = 0


相关文档:

Online active users counter in ASP.NET


Online active users counter in ASP.NET
With this tool which is written for ASP.NET, it is possible to count the number of online users, members and guest users in web sites.
Installation
The tool installation is very simple and only takes a few minutes.
Step one - Add Reference:
After downlo ......

使用WebClient自动填写并提交ASP.NET页面表单


使用WebClient自动填写并提交ASP.NET页面表单
      在.NET中通过程序填写和提交表单还是比较简单。比如,要提交一个如下图所示的登录表单:
           
填写和提交以上表单的代码如下:
      &nb ......

asp.net 关闭网页代码

2种方法
一、linkbutton的单击事件里关闭页面,拼接代码就是了
补充,不可能,我自己试过,再补充一下
1.关闭时提示“是否关闭”
Response.Write("<script language:javascript>javascript:window.close();</script>");
2.直接关闭不提示
Response.Write("<script language:javascrip ......

ASP.NET Cookie使用


1.什么是cookie?
cookie 是一小段文本信息,伴随用户请求,在web服务器和浏览器之间传递。用户每次访问站点的时候,
web应用程序都可以读取cookie包含的信息。
假设在用户请求您的网站的某个页面时,您的应用程序不仅是返回请求的页面。同时也返回一个包含日期
和时间的cookie。用户的浏览器在获得页面的同时也获得 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号