I've used BotDetect before to utilize a captcha on an asp WEBFORM
, but now when I try to add BotDetect to another Asp WEBFORM
project using NuGet, I'm greeted with an 'Object Reference not set to an instance of an object' error upon debugging.
我用BotDetect之前利用在ASP WEBFORM验证码,但现在当我尝试BotDetect添加到使用的NuGet另一个ASP WEBFORM项目,我招呼着一个“对象引用未设置到对象的实例”错误在调试。
I cannot load my page nor get any breaks to occur. It seems to be failing when it tries to do an Application insights request GET of my form page. It then throws an unhanded exception in System.Web.dll
我无法加载我的页面,也不会发生任何中断。当它尝试执行我的表单页面的应用程序见解请求GET时似乎失败了。然后它会在System.Web.dll中抛出一个无法处理的异常
However, that being said, when I try to run he debugger, I'm still met with a 'Object Reference not set to an instance of an object' error, but it references BotDetect.Web.UI.WebFormsCaptcha.OnInit(EventArgs e)
然而,话虽这么说,当我尝试运行他的调试器时,我仍然遇到了'对象引用未设置为对象的实例'错误,但它引用了BotDetect.Web.UI.WebFormsCaptcha.OnInit(EventArgs e) )
I've removed the BotDetect package, re-added the assemblies, tried to add the assemblies from the working project, and I've tried to recreate the project from the ground up to see if I maybe had mis-configured something. Nothing seems to work.
我已经删除了BotDetect包,重新添加了程序集,试图从工作项目添加程序集,我试图从头开始重新创建项目,看看我是否有错配置的东西。似乎没什么用。
I currently have BotDetect
and BotDetect.Web.MVC
from the NuGet package (version 4.0.1) and I've checked to make sure I'm using the .net 4.5 versions with my .net 4.5 project.
我目前有来自NuGet包(版本4.0.1)的BotDetect和BotDetect.Web.MVC,我已经检查过以确保我在我的.net 4.5项目中使用.net 4.5版本。
I've checked my Packages.config and I can see:
我已经检查了我的Packages.config,我可以看到:
<package id="Captcha" version="4.0.1" targetFramework="net452" />
Below is my code that references the BotDetect Captcha. It is a MasterPage web form, but the Captcha resides in a content placeholder since we interact with it after the master has been rendered.
下面是我的代码,它引用了BotDetect Captcha。它是一个MasterPage Web表单,但Captcha驻留在内容占位符中,因为我们在呈现主表单后与它进行交互。
I'm just not sure what else I can do to fix this, any suggestions?
我只是不确定我还能做些什么来解决这个问题,有什么建议吗?
ASP Form Page
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 Form Page CODE BEHIND
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
1 个解决方案
#1
1
So I've since spoken to the devs of BotDetect and it turned out that this is in fact a bug with their current release.
所以我已经和BotDetect的开发者交谈了,事实证明这实际上是他们当前发布的一个错误。
You currently cannot set the UserInputControlID property in a content page (Web form with master page) with BotDetect (v4.0.1). There will be a patch for this in the next version.
您当前无法使用BotDetect(v4.0.1)在内容页面(带有母版页的Web表单)中设置UserInputControlID属性。在下一个版本中会有一个补丁。
In the meantime, based on the code I posted, you can set it programmatically in the codebehind (VB).
在此期间,根据我发布的代码,您可以在代码隐藏(VB)中以编程方式设置它。
CODE BEHIND (in page_prerender)
代码背后(在page_prerender中)
ExampleCaptcha.UserInputID = CaptchaCodeTextBox.ClientID
ExampleCaptcha.UserInputID = CaptchaCodeTextBox.ClientID
You may also need to replace
您可能还需要更换
isHuman = ExampleCaptcha.Validate()
With
同
isHuman = ExampleCaptcha.Validate(CaptchaCodeTextBox.Text.Trim())
CONTENT WEB FORM
内容网页表格
<BotDetect:WebFormsCaptcha runat="server" ID="ExampleCaptcha" />
#1
1
So I've since spoken to the devs of BotDetect and it turned out that this is in fact a bug with their current release.
所以我已经和BotDetect的开发者交谈了,事实证明这实际上是他们当前发布的一个错误。
You currently cannot set the UserInputControlID property in a content page (Web form with master page) with BotDetect (v4.0.1). There will be a patch for this in the next version.
您当前无法使用BotDetect(v4.0.1)在内容页面(带有母版页的Web表单)中设置UserInputControlID属性。在下一个版本中会有一个补丁。
In the meantime, based on the code I posted, you can set it programmatically in the codebehind (VB).
在此期间,根据我发布的代码,您可以在代码隐藏(VB)中以编程方式设置它。
CODE BEHIND (in page_prerender)
代码背后(在page_prerender中)
ExampleCaptcha.UserInputID = CaptchaCodeTextBox.ClientID
ExampleCaptcha.UserInputID = CaptchaCodeTextBox.ClientID
You may also need to replace
您可能还需要更换
isHuman = ExampleCaptcha.Validate()
With
同
isHuman = ExampleCaptcha.Validate(CaptchaCodeTextBox.Text.Trim())
CONTENT WEB FORM
内容网页表格
<BotDetect:WebFormsCaptcha runat="server" ID="ExampleCaptcha" />