c# - ASP.Net 注册表中的 MS Captcha 超时持续时间

标签 c# asp.net timeout captcha

我目前在注册表中使用 MS 验证码。如果在一分钟内提交表单,它将完美运行。但有时,用户填写完表格后搜索要上传的文件,当他们最终提交表格时,他们会收到服务器错误,如下所示:

[NullReferenceException: Object reference not set to an instance of an object.] MSCaptcha.CaptchaControl.ValidateCaptcha(String userEntry) +438

单击提交按钮时,我调用 ValidateCaptcha 如下:

Captcha1.ValidateCaptcha(txtCaptcha.Text.Trim());

有人可以帮我处理这个异常吗?提前致谢。

最佳答案

已经看到,如果您没有设置 ErrorInputTooFast 和 ErrorInputTooSlow 消息,代码会在 CaptchaMaxTimeout 时间段过去时抛出“NullReferenceException”。

我还设置了以下属性,以便在没有 NullReferenceException 的情况下正常工作

ErrorInputTooFast="图像文本输入速度过快。" ErrorInputTooSlow="图像文本输入速度太慢。"

我的实现如下,我将 CaptchaMaxTimeout 设置为 20 秒以查看此问题是否仍然存在。

<uc:CaptchaControl ID="CaptchaUserControl" runat="server" Height="50px" ValidationGroup="PageValidationGroup"
                                        CustomValidatorErrorMessage="The text you entered did not match up with the image provided"
                                        Width="180px" CaptchaLength="5" FontColor="#000000" BackColor="#e6db55" NoiseColor="#26557f"
                                        CaptchaLineNoise="None" CaptchaFontWarping="Low" ImageTag="border='1'" CaptchaBackgroundNoise="Medium"
                                        ErrorInputTooFast="Image text was typed too quickly. " ErrorInputTooSlow="Image text was typed too slowly."
                                        CaptchaMaxTimeout="20" CaptchaMinTimeout="2" EnableViewState="False" />
                                   <asp:TextBox ID="CapthaTextBox" runat="server" MaxLength="10" Width="180px"  AutoCompleteType="Disabled"/>

代码隐藏

 private void AppendValidationErrorMessage( string message)
    {
        var cv = new CustomValidator(); 
        cv.IsValid = false;
        cv.ErrorMessage = message;
        cv.ValidationGroup = "PageValidationGroup";
        this.Page.Validators.Add(cv);
    }

    protected void SubmitButtonClick(object sender, EventArgs e)
    {
        try
        {
            this.CaptchaUserControl.ValidateCaptcha(CapthaTextBox.Text.GetTrimValue());
            if (!this.CaptchaUserControl.UserValidated)
            {
                this.AppendValidationErrorMessage(this.CaptchaUserControl.CustomValidatorErrorMessage);
            }
        }
        catch (Exception)
        {
            this.AppendValidationErrorMessage(
                "Captcha expired please please reload the page.Note: please copy the data before refreshing data");
        }
        this.CapthaTextBox.Text = string.Empty;
        if (this.Page.IsValid) //&& this.CaptchaUserControl.UserValidated
        {
            //do something

        }
    }

关于c# - ASP.Net 注册表中的 MS Captcha 超时持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17232819/

相关文章:

python - 在 Python 中使用多处理创建超时函数

c++ - 当 CPU 负载过大时 pthread_cond_timedwait 超时

C# 反射 : Get *all* active assemblies in a solution?

Java HTTP GET 响应等待直到超时

c# - 卡在表达式树中

将默认字符串参数传递给属性导致的 C# 编译器错误

c# - 模态弹出扩展器关闭上的部分渲染更新面板

asp.net - 有多少用户可以打开与 Microsoft Access 的连接?

c# - 使用 CsvHelper,如果第一列的值等于 0,如何映射到第二列

c# - 用于特定用例的 String.Format