开发者

Recaptcha not working in asp.net application

I'm trying to user recaptcha control in my application. For some reason it's all the time valid. no matter what values I put in recaptcha field it's all the time valid. Any idea what I'm missing?

here is my code

<%@ Control Language="C#" CodeBehind="RegisterControl.ascx.cs" AutoEventWireup="true"
    Inherits="UserControls.RegisterControl" %>
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
<asp:Panel ID="PlReg" runat="server" DefaultButton="CreateUserButton">
    <div class="Reg_Wrapper">
        <span class="failureNotification">

            <asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
        </span>
        <div class="Clear">
        </div>
        <div class="Reg_ControlName">
            <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label></div>
        <div class="Reg_Control">
            <asp:TextBox ID="TxtUserName" runat="server" CssClass="textEntry"></asp:TextBox>
            <asp:RequiredFieldValidator Display="Dynamic" ID="UserNameRequired" runat="server"
                ControlToValidate="TxtUserName" CssClass="failureNotification" ErrorMessage="User Name is required."
                ToolTip="User Name is required." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
        </div>
        <div class="Clear">
        </div>
        <div class="Reg_ControlName">
            <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label></div>
        <div class="Reg_Control">
            <asp:TextBox ID="TxtEmail" runat="server" CssClass="textEntry"></asp:TextBox>
            <asp:RequiredFieldValidator Display="Dynamic" ID="EmailRequired" runat="server" ControlToValidate="TxtEmail"
                CssClass="failureNotification" ErrorMessage="E-mail is required." ToolTip="E-mail is required."
                ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RevEmail" ControlToValidate="TxtEmail" runat="server"
                ErrorMessage="*" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
            <img src="/Images/required.png" alt="Required" />
            </asp:RegularExpressionValidator>
        </div>
        <div class="Clear">
        </div>
        <div class="Reg_ControlName">
            <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label></div>
        <div class="Reg_Control">
            <asp:TextBox ID="TxtPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
            <asp:RequiredFieldValidator Display="Dynamic" ID="PasswordRequired" runat="server"
                ControlToValidate="TxtPassword" CssClass="failureNotification" ErrorMessage="Password is required."
                ToolTip="Password is required." ValidationGroup="RegisterUserValidationGroup"><img 开发者_高级运维src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
        </div>
        <div class="Clear">
        </div>
        <div class="Reg_ControlName">
            <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Conf. Password:</asp:Label></div>
        <div class="Reg_Control">
            <asp:TextBox ID="TxtConfirmPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
            <asp:RequiredFieldValidator ControlToValidate="TxtConfirmPassword" CssClass="failureNotification"
                Display="Dynamic" ErrorMessage="Confirm Password is required." ID="ConfirmPasswordRequired"
                runat="server" ToolTip="Confirm Password is required." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
            <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="TxtPassword"
                ControlToValidate="TxtConfirmPassword" CssClass="failureNotification" Display="Dynamic"
                ErrorMessage="The Password and Confirmation Password must match." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:CompareValidator>
        </div>
        <div class="Clear">
        </div>
        <div class="Reg_ControlName">
            &nbsp;</div>
        <div class="Reg_Control">
            <recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="my public key"
                PrivateKey="my private key" Theme="white" />
        </div>
        <div class="Clear">
        </div>
        <div class="Reg_ControlName">
            &nbsp;</div>
        <div class="Reg_Control">
            <asp:Button ID="CreateUserButton" role="button" runat="server" CommandName="MoveNext"
                Text="Create User" ValidationGroup="RegisterUserValidationGroup" CssClass="Reg_Button"
                OnClick="CreateUserButton_Click" /></div>
        <div class="Clear">
        </div>
    </div>
</asp:Panel>

serverside

protected void CreateUserButton_Click(object sender, EventArgs e)
{
    if(Page.IsValid)
    {
        ErrorMessage.Text = "page is valid";
    }
    else
    {
        ErrorMessage.Text = "page is not valid";
    }
}


Here's one that works for me. Be sure to insert correct keys on server:

<recaptcha:RecaptchaControl ID="recaptcha" Theme="clean" runat="server"
    PublicKey="hiddenxxx" TabIndex="7" ToolTip="Accessible CAPTCHA" 
        privateKey="hiddenxxx" />
<asp:Label CssClass="captchaLabel" ID="lblResult" runat="server" />

As you can see, I usually keep the CAPTCHA error message separate from the other messages.

Code-behind:

if(Page.IsValid)
{
    ...
}
else
{
    lblResult.Text = "Incorrect!";
    lblResult.ForeColor = System.Drawing.Color.Red;
}


i dont think check captcha validation out on page load there should be submit button that you have and you check it out in click event of the button, this is how i use. i think you should check links blove...

http://code.google.com/intl/tr-TR/apis/recaptcha/docs/aspnet.html

http://www.codeproject.com/KB/custom-controls/CaptchaControl.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜