在ASP.Net登记表MS验证码超时时间 [英] MS Captcha timeout duration in registration form in ASP.Net

查看:407
本文介绍了在ASP.Net登记表MS验证码超时时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用MS验证码的登记表。如果形式在一分钟内提交了它完美的作品。但有时,填写表单用户,然后搜索文件上传,之后当他们终于提交表单,他们得到服务器错误如下:


  

[NullReferenceException:未将对象引用未设置为一个实例
  ]对象。MSCaptcha.CaptchaControl.ValidateCaptcha(字符串userEntry)
  438


在提交按钮的点击,我称之为 ValidateCaptcha 如下:

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

有人可以帮助我处理这个异常?先谢谢了。


解决方案

它已经看到,如果你没有设置ErrorInputTooFast和ErrorInputTooSlow消息code抛出的NullReferenceException当CaptchaMaxTimeout时间段已经过去了。

我已经设置了以下属性,以及得到这个工作没有的NullReferenceException

ErrorInputTooFast =图片文字输入是太快。
ErrorInputTooSlow =图片文字输入是太慢了。

我的实现如下。我将作为CaptchaMaxTimeout 20秒,看看这问题仍然存在。

 < UC:CaptchaControl ID =CaptchaUserControl=服务器HEIGHT =50像素的ValidationGroup =PageValidationGroup
                                        CustomValidatorErrorMessage =您输入的文本并没有使用所提供的图像匹配
                                        WIDTH =180像素CaptchaLength =5FONTCOLOR =#000000背景色=#e6db55NoiseColor =#26557f
                                        CaptchaLineNoise =无CaptchaFontWarping =低ImageTag =BORDER ='1'CaptchaBackgroundNoise =中
                                        ErrorInputTooFast =图片文字输入是太快。ErrorInputTooSlow =图片文字输入是太慢了。
                                        CaptchaMaxTimeout =20CaptchaMinTimeout =2的EnableViewState =假/>
                                   < ASP:文本框ID =CapthaTextBox=服务器MAXLENGTH =10WIDTH =180像素AutoCompleteType =已禁用/>

后面

code

 私人无效AppendValidationErrorMessage(字符串消息)
    {
        变种CV =新的CustomValidator();
        cv.IsValid = FALSE;
        cv.ErrorMessage =消息;
        cv.ValidationGroup =PageValidationGroup;
        this.Page.Validators.Add(CV);
    }    保护无效SubmitButtonClick(对象发件人,EventArgs的发送)
    {
        尝试
        {
            this.CaptchaUserControl.ValidateCaptcha(CapthaTextBox.Text.GetTrimValue());
            如果(!this.CaptchaUserControl.UserValidated)
            {
                this.AppendValidationErrorMessage(this.CaptchaUserControl.CustomValidatorErrorMessage);
            }
        }
        赶上(例外)
        {
            this.AppendValidationErrorMessage(
                验证码已过期,请请重新载入页面。注意:请刷新数据之前将数据复制);
        }
        this.CapthaTextBox.Text =的String.Empty;
        如果(this.Page.IsValid)//&放大器;&安培; this.CaptchaUserControl.UserValidated
        {
            //做一点事        }
    }

I am currently using MS Captcha in a registration form. It works perfectly if the form is submitted within a minute. But sometimes, after filling in the form the user then searches for documents to upload, and when they finally submit the form, they get server error as below:

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

On submit button click, I call the ValidateCaptcha as below:

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

Can someone help me in handling this exception? Thanks in advance.

解决方案

It has been seen that if you have not set ErrorInputTooFast and ErrorInputTooSlow messages the code throws 'NullReferenceException' when the CaptchaMaxTimeout time period has passed.

I have set the following properties as well to get this working without NullReferenceException

ErrorInputTooFast="Image text was typed too quickly." ErrorInputTooSlow="Image text was typed too slowly."

my implementation is as below and i have set CaptchaMaxTimeout as 20 sec to see if this issue persists.

<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"/>

code behind

 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

        }
    }

这篇关于在ASP.Net登记表MS验证码超时时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆