1

「お問い合わせ」ページにキャプチャ機能を作成しました。エンド ユーザーは、メッセージを送信する前に、指定されたキャプチャを確認する必要があります。キャプチャの検証は正しいです。つまり、キャプチャが正しいかどうかに関係なく読み取ります。問題は、送信ボタンをクリックして間違ったキャプチャを入力しようとすると、「無効なキャプチャ」と表示されてもメッセージが通過することです。これに関するトリックはありますか?

ここに私のcontact.aspx、特に送信ボタンとキャプチャがあります:

<asp:TextBox ID="txtCaptcha" runat="server" placeholder="Enter captcha"></asp:TextBox>

<cc1:CaptchaControl ID="Captcha1" runat="server" CaptchaBackgroundNoise="Low" CaptchaLength="5"
        CaptchaHeight="60" CaptchaWidth="300" CaptchaMinTimeout="5" CaptchaMaxTimeout="240"
        FontColor="#D20B0C" NoiseColor="#B1B1B1" />

<asp:CustomValidator ID="CustomValidator1" ErrorMessage="Invalid. Please try again." OnServerValidate="ValidateCaptcha"
        runat="server" />

        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                                        ErrorMessage="Captcha is required." Display="Dynamic" ControlToValidate="txtCaptcha" 
                                        ForeColor="Red"></asp:RequiredFieldValidator>

送信ボタンは次のとおりです。

<asp:Button ID="Button1" runat="server" Text="Sumbit" 
                                class="btn btn-primary btn-lg" onclick="Button1_Click"/>

そして連絡先 aspx.cs

protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            SqlConnection conn = new SqlConnection("Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True");
            conn.Open();
            string insertQuery = "insert into UserMessage(FirstName,LastName,EmailAddress,Phone,Message)values(@FirstName,@LastName,@EmailAddress,@Phone,@Message)";
            SqlCommand scm = new SqlCommand(insertQuery, conn);
            scm.Parameters.AddWithValue("@FirstName", txtboxFN.Text);
            scm.Parameters.AddWithValue("@LastName", txtboxLN.Text);
            scm.Parameters.AddWithValue("@EmailAddress", txtboxAddress.Text);
            scm.Parameters.AddWithValue("@Phone", txtPhone.Text);
            scm.Parameters.AddWithValue("@Message", txtMessage.Text);

            scm.ExecuteNonQuery();
            Label1.Text = "Message Sent Successfully";
            conn.Close();
        }
        catch (Exception ex)
        {
            Response.Write("Error:" + ex.ToString());
        }
    }
    protected void ValidateCaptcha(object sender, ServerValidateEventArgs e)
    {
        Captcha1.ValidateCaptcha(txtCaptcha.Text.Trim());
        e.IsValid = Captcha1.UserValidated;
        if (e.IsValid)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Valid Captcha!');", true);
        }
    }
4

0 に答える 0