我以前使用过BotDetect在asp上使用captcha
WEBFORM
,但现在当我尝试将BotDetect添加到另一个Asp时
WEB模板
项目使用NuGet时,我在调试时遇到一个“Object Reference not set to an instance of an Object”错误。
我无法加载页面,也无法出现任何中断。当它尝试执行Application insights请求GET我的表单页面时,似乎失败了。然后在System.Web.dll中抛出一个未处理的异常
尽管如此,当我尝试运行调试器时,仍然会遇到“Object Reference not set to an instance of a Object”错误,但它引用
BotDetect.Web.UI.WebFormsCaptcha.OnInit(EventArgs e)
我删除了BotDetect包,重新添加了程序集,尝试从工作项目中添加程序集,并且尝试从头开始重新创建项目,以查看我是否配置错误。似乎什么都不管用。
我目前有
BotDetect
和
BotDetect.Web.MVC
从NuGet包(版本4.0.1),我已经检查过,以确保在我的.net 4.5项目中使用.net 4.5版本。
我已经检查了我的包裹。config,我可以看到:
<package id="Captcha" version="4.0.1" targetFramework="net452" />
下面是我引用BotDetect Captcha的代码。它是一个MasterPage web表单,但Captcha驻留在内容占位符中,因为我们在呈现主控形状后与它交互。
我只是不确定我还能做什么来解决这个问题,有什么建议吗?
ASP表单页
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<fieldset>
<legend>ASP.NET WebForm CAPTCHA Validation</legend>
<p class="prompt">
<label for="CaptchaCodeTextBox">Retype the characters from the picture:</label></p>
<BotDetect:WebFormsCaptcha runat="server" ID="ExampleCaptcha"
UserInputControlID="CaptchaCodeTextBox" />
<div class="validationDiv">
<asp:TextBox ID="CaptchaCodeTextBox" runat="server"></asp:TextBox>
<asp:Button ID="ValidateCaptchaButton" runat="server" />
<asp:Label ID="CaptchaCorrectLabel" runat="server" CssClass="correct"></asp:Label>
<asp:Label ID="CaptchaIncorrectLabel" runat="server" CssClass="incorrect"></asp:Label>
</div>
</fieldset>
后面的ASP表单页代码
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
' initial page setup
If Not IsPostBack Then
' set control text
ValidateCaptchaButton.Text = "Validate"
CaptchaCorrectLabel.Text = "Correct!"
CaptchaIncorrectLabel.Text = "Incorrect!"
' these messages are shown only after validation
CaptchaCorrectLabel.Visible = False
CaptchaIncorrectLabel.Visible = False
End If
If IsPostBack Then
' validate the Captcha to check we're not dealing with a bot
Dim isHuman As Boolean
isHuman = ExampleCaptcha.Validate()
If isHuman Then
CaptchaCorrectLabel.Visible = True
CaptchaIncorrectLabel.Visible = False
Else
CaptchaCorrectLabel.Visible = False
CaptchaIncorrectLabel.Visible = True
End If
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim HF As HiddenField = DirectCast(Page.Master.FindControl("HF1"), HiddenField)
If Not IsPostBack Then
SetInitialRow()
ElseIf HF.Value = "AddNewRow" Then
AddNewRowToGrid()
Else
btnSubmit_Click()
End If
Done:
End Sub