新建一个Aspx文件用来提供验证码图片,例如:ValidCode.aspx,PageLoad加上此事件
protected void Page_Load(object sender, EventArgs e)
{
Session["ValidCode"] = Socansoft.ValidCode.CreateImage(4, Socansoft.ValidCode.ValidType.Numeric);
}
{
Session["ValidCode"] = Socansoft.ValidCode.CreateImage(4, Socansoft.ValidCode.ValidType.Numeric);
}
此页面就是提供图片源的页面了,测试一下,前台HTML
<asp:Image ID="Image1" runat="server" ImageUrl="/WebBBS/ValidCode.aspx" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
后台代码
protected void Button1_Click(object sender, EventArgs e)
{
bool b = TextBox1.Text == Session["ValidCode"].ToString();
Response.Write(b.ToString());
}
{
bool b = TextBox1.Text == Session["ValidCode"].ToString();
Response.Write(b.ToString());
}