62,067
社区成员
发帖
与我相关
我的任务
分享
//图片验证在第一次登陆的时候,明明输入正确,却还提示验证码错误,在第二次输入就没有这个问题了
protected void Page_Load(object sender, EventArgs e)
{
//读取图片验证码程序-----------------------
this.btnimage.ImageUrl = "TextVerify.aspx";
}
protected void Page_Load(object sender, EventArgs e)
{
this.GenImg(this.GenCode(4));
////将验证码存储到session中,以便需要时进行验证
Session["image"] = this.GenCode(4);
}
//任意产生4个验证码
private string GenCode(int num)
{
//定义一个验证码数组
string[] source ={ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
string code = "";
Random rd = new Random();
for (int i = 0; i < num; i++)
{
code += source[rd.Next(0, source.Length)];
}
return code;
}
//生成图片
private void GenImg(string code)
{
//定义一个画板
Bitmap myPalette = new Bitmap(50, 18);
//在画板上定义绘图的实例
Graphics gh = Graphics.FromImage(myPalette);
//定义一个矩形
Rectangle rc = new Rectangle(0, 0, 50, 18);
//填充矩形
gh.FillRectangle(new SolidBrush(Color.Black), rc);
//在矩形内画出字符串
gh.DrawString(code, new Font("Arial", 11), new SolidBrush(Color.White), rc);
//将图片显示出来
myPalette.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
gh.Dispose();
myPalette.Dispose();
}
protected void Page_Load(object sender, EventArgs e)
{
this.GenImg(this.GenCode(4));
Session["image"] = this.GenCode(4);
}
protected void Page_Load(object sender, EventArgs e)
{
string code = this.GenCode(4);
this.GenImg(code);
Session["image"] = code ;
}
private string GenCode(int num)
{
//定义一个验证码数组
string[] source ={ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
string code = "";
Random rd = new Random();
for (int i = 0; i < num; i++)
{
code += source[rd.Next(0, source.Length)];
}
///把session放在这里
Session["image"] = code;
return code;
}
private string GenCode(int num)
{
//定义一个验证码数组
string[] source ={ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
string code = "";
Random rd = new Random();
for (int i = 0; i < num; i++)
{
code += source[rd.Next(0, source.Length)];
}
///把session放在这里
Session["image"] = this.GenCode(4);
return code;
}
protected void Page_Load(object sender, EventArgs e)
{
this.GenImg(this.GenCode(4));
////将验证码存储到session中,以便需要时进行验证
Session["image"] = this.GenCode(4);
}
protected void Page_Load(object sender, EventArgs e)
{
string code = this.GenCode(4);
this.GenImg(code);
////将验证码存储到session中,以便需要时进行验证
Session["image"] = code ;
}