您的位置:首页 > 编程语言 > ASP

ASP.NET——基础 7、用注册码,防止暴力注册

2013-01-07 15:21 369 查看
1、新建一个一般处理程序ashx,在一般处理程序中使用Session,要为其实现的如下接口

System.Web.SessionState.IRequiresSessionState


2、一般处理程序的任务有两个,代码如下:

生成一个验证码

把验证码写入Session

content.Response.ContentType="image/JPEG";
using(System.Drawing.Bitmapbitmap=newSystem.Drawing.Bitmap(100,50))
{
using(System.Drawing.Graphicsg=System.Drawing.Graphics(bitmap))
{
using(Fontfont=newSystem.Drawing.Font("宋体",12))
{
using(PointFpoint=newSystem.Drawing.PointF(0,10))
{
Randomrand=newRandom();
intcode=rand.Next(1000,9999);
stringstrCode=code.ToString();
HttpContext.Current.Session["Code"]=strCode;
g.DrawString(strCode,font,System.Drawing.Brush.Green,point);
bitmap.Save(content.Response.OutputStream,System.Drawing.Image.ImageFormat.Jpeg);
}
}
}
}




3、CS中的代码如下:

stringCode=Convert.ToString(Session["Code"]);
if(code==TextBox1.Text)
{
Response.Write("验证码输入正确!");
}


4、点击刷新

<imgsrc="YZM.ashx"onclick="this.src='YZM.ashx?aaa='+newDate()"/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: