.NET1.1项目中的Recaptcha验证器
我试图在.net 1.1项目上使用旧版本的Recaptcha验证器,可以在以下位置找到: 我的代码与上面链接中的示例非常相似:.NET1.1项目中的Recaptcha验证器,.net,validation,.net-1.1,recaptcha,.net,Validation,.net 1.1,Recaptcha,我试图在.net 1.1项目上使用旧版本的Recaptcha验证器,可以在以下位置找到: 我的代码与上面链接中的示例非常相似: <asp:TextBox ID="EmailAddress" runat="server"></asp:TextBox> <recatpcha:RecaptchaValidator ID="RecaptchaValidator1" runat="server" Theme="Clean" PublicKey="xxxxxxxxxxxxxx"
<asp:TextBox ID="EmailAddress" runat="server"></asp:TextBox>
<recatpcha:RecaptchaValidator ID="RecaptchaValidator1" runat="server" Theme="Clean" PublicKey="xxxxxxxxxxxxxx" PrivateKey="xxxxxxxxxx" ControlToValidate="EmailAddress"></recatpcha:RecaptchaValidator>
<asp:Button ID="Button1" runat="server" Text="Button" CausesValidation="true" OnClick="Button1_Click" />
我想要的行为很简单:在页面加载时,用户会看到一个字段来输入他们的电子邮件地址,一个要完成的验证码,以及一个提交按钮。提交时,如果在我们的数据库中找不到具有该电子邮件地址的用户,或者验证码回答不正确,则会显示新的验证码以及相应的错误消息。否则,他们将收到一封关于如何重置密码的电子邮件
主要问题是页面加载时不会显示验证码。但是,当我点击submit按钮触发Page.Validate()时,页面会重新加载,并显示验证码
基于此,我想我应该尝试另一种方法,在Page load事件中调用Page.Validate(),以使验证码最初显示出来。这几乎奏效了:验证码出现在第一个页面加载时,但是当提交了无效的电子邮件以及正确的验证码答案时,验证码会在页面重新加载时消失,但当然,电子邮件无法发送
我如何在最初点击页面时强制提供验证码,或者在输入无效电子邮件地址时阻止提交验证码?好吧,这并不漂亮,但我已经让它工作了 由于使用RecaptchaValidator标记没有按我希望的方式工作,因此我使用recaptcha AJAX API()将小部件嵌入页面:
$(document).ready(function() {
Recaptcha.create("<public key>",
"ReCaptcha", {
theme: "clean",
callback: Recaptcha.focus_response_field
});
});
$(文档).ready(函数(){
Recaptcha.create(“”,
“雷帕查”{
主题:“清洁”,
回调:Recaptcha.focus\u response\u字段
});
});
然后,由于所有需要使用recaptcha服务器验证的数据(challenge、publickey等。此处有更多信息:)都在文章中,因此我实例化了一个新的RecaptchaValidator,设置其余属性,并调用该方法来验证用户响应
protected void Submit_Click(object sender, System.EventArgs e)
{
RecaptchaValidator RecaptchaValidator1 = new RecaptchaValidator();
RecaptchaValidator1.Page = this;
RecaptchaValidator1.PrivateKey = "<private key>";
RecaptchaValidator1.PublicKey = "<public key>";
bool CaptchaPassed = RecaptchaValidator1.ValidateUserResponse();
if (CaptchaPassed)
{
//hide the captcha, do some stuff
}
}
protectedvoid提交\u单击(对象发送者,System.EventArgs e)
{
RecaptchaValidator RecaptchaValidator1=新的RecaptchaValidator();
RecaptchaValidator1.Page=此;
retaptchavalidator1.PrivateKey=“”;
retaptchavalidator1.PublicKey=“”;
bool CaptchaPassed=RecaptchaValidator1.ValidateUserResponse();
如果(已批准)
{
//隐藏验证码,做些事情
}
}
诚然,有点老套,但它完成了任务
注意-我在问题中提到了这一点,但只是重申一下:服务器端代码使用旧的.NET 1.1兼容的recaptcha插件。插件代码的链接在问题中。我有令人尴尬的低代表性,不能再使用任何超链接>好吧,这不漂亮,但我得到了它的工作 由于使用RecaptchaValidator标记没有按我希望的方式工作,因此我使用recaptcha AJAX API()将小部件嵌入页面:
$(document).ready(function() {
Recaptcha.create("<public key>",
"ReCaptcha", {
theme: "clean",
callback: Recaptcha.focus_response_field
});
});
$(文档).ready(函数(){
Recaptcha.create(“”,
“雷帕查”{
主题:“清洁”,
回调:Recaptcha.focus\u response\u字段
});
});
然后,由于所有需要使用recaptcha服务器验证的数据(challenge、publickey等。此处有更多信息:)都在文章中,因此我实例化了一个新的RecaptchaValidator,设置其余属性,并调用该方法来验证用户响应
protected void Submit_Click(object sender, System.EventArgs e)
{
RecaptchaValidator RecaptchaValidator1 = new RecaptchaValidator();
RecaptchaValidator1.Page = this;
RecaptchaValidator1.PrivateKey = "<private key>";
RecaptchaValidator1.PublicKey = "<public key>";
bool CaptchaPassed = RecaptchaValidator1.ValidateUserResponse();
if (CaptchaPassed)
{
//hide the captcha, do some stuff
}
}
protectedvoid提交\u单击(对象发送者,System.EventArgs e)
{
RecaptchaValidator RecaptchaValidator1=新的RecaptchaValidator();
RecaptchaValidator1.Page=此;
retaptchavalidator1.PrivateKey=“”;
retaptchavalidator1.PublicKey=“”;
bool CaptchaPassed=RecaptchaValidator1.ValidateUserResponse();
如果(已批准)
{
//隐藏验证码,做些事情
}
}
诚然,有点老套,但它完成了任务
注意-我在问题中提到了这一点,但只是重申一下:服务器端代码使用旧的.NET 1.1兼容的recaptcha插件。插件代码的链接在问题中。我有令人尴尬的低代表性,不能再使用任何超链接>。