我正在尝试写验证码首先我写了asp然后我可以把它作为图像。问题是图像和会话不等于会话在image.i之前找不到问题的原因。我可以解决这个问题?
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public partial class botdetect_captcha : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//create image
Bitmap bmp = new Bitmap(100, 30);
//create object to draw
Graphics g = Graphics.FromImage(bmp);
//image background
g.Clear(Color.LightBlue);
//randomly string
string metin = RastgeleKelime();
//send to session for validation
Session["gResim"] = metin;
//create font for image
Font font = new Font("Comic Sans MS", 14);
g.DrawString(metin, font, Brushes.DarkBlue, 4, 1);
//draw randomly three lines
Random rnd = new Random();
g.DrawLine(Pens.DarkSlateGray, rnd.Next(0, 100), rnd.Next(0, 30), rnd.Next(0, 100), rnd.Next(0, 30));
g.DrawLine(Pens.DarkRed, rnd.Next(0, 100), rnd.Next(0, 30), rnd.Next(0, 100), rnd.Next(0, 30));
g.DrawLine(Pens.DarkOrange, rnd.Next(0, 100), rnd.Next(0, 30), rnd.Next(0, 100), rnd.Next(0, 30));
//make response
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
}
public string RastgeleKelime()
{
string kelime = "";
Random rnd = new Random();
for (int i = 0; i < 6; i++)
{
kelime += ((char)rnd.Next('A', 'Z')).ToString();
}
return kelime;
}
}
答案 0 :(得分:0)
我会通过以下步骤“修复它”:
将图像创建移动到自定义处理程序。创建图像时,在会话或其他位置存储唯一值。
添加图片标记,将源设置为处理程序。
为用户添加输入控件以输入回复
提交对服务器的响应
服务器将响应与唯一值进行比较。
处理回应。