0
我想整合谷歌reCAPTCHA與我的網站的註冊表格。我找到了a solution at CodeProject.我已經下載了dll並將其添加到項目引用文件夾中。谷歌reCAPTCHA的dll
下面是一些代碼片段:
HTML:
<asp:CreateUserWizard ID="CreateUserWizard2" OnCreatingUser="CreateUserWizard2_CreatingUser" OnCreateUserError="CreateUserWizard2_CreateUserError" oncreateduser="CreateUserWizard2_CreatedUser" ContinueDestinationPageUrl="/Account/MyDashboard.aspx" ContinueButtonStyle-CssClass="btn btn-default col-md-3 btn-search input-password" runat="server" RequireEmail="false" Width="100%" RenderOuterTable="false" QuestionRequiredErrorMessage="false">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server" >
<ContentTemplate>
<h5 class="text-center">Please complete the following fields to register for an account</h5>
<br />
<h5 class="right">Login Details</h5>
<br/>
<asp:TextBox ID="UserName" runat="server" class="form-control height-fix" placeholder="EMAIL" ></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" TextMode="Email" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ForeColor="red" ValidationGroup="CreateUserWizard2" />
<asp:TextBox ID="Password" runat="server" class="form-control height-fix" placeholder="PASSWORD" TextMode="Password" />
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ForeColor="red" ValidationGroup="CreateUserWizard2" />
<asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password" class="form-control height-fix" placeholder="REPEAT PASSWORD" />
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." ForeColor="red" ValidationGroup="CreateUserWizard2" />
<cc1:GoogleReCaptcha ID="ctrlGoogleReCaptcha" runat="server" PublicKey="keyinhere" PrivateKey="secretinheree" />
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="false" />
</ContentTemplate>
<CustomNavigationTemplate>
<asp:Button ID="StepNextButton" runat="server" class="btn btn-md btn-sign-in btn-block btn-padding" CommandName="MoveNext" Text="SUBMIT" ValidationGroup="CreateUserWizard2" />
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep2" runat="server" AllowReturn="true" />
</WizardSteps>
</asp:CreateUserWizard>
C#:
...
using GoogleReCaptcha;
namespace WebOnline
{
public partial class PublicAccess : System.Web.UI.MasterPage
{
private NLog.Logger _log = NLog.LogManager.GetCurrentClassLogger();
protected void CreateUserWizard2_CreatedUser(object sender, EventArgs e)
{
// Validation code block goes in here.
}
[Import]
IUnitOfWork IUnitOfWork;
private UnitOfWork _UnitOfWork;
private UnitOfWork UnitOfWork
{
get
{
if (_UnitOfWork == null)
{
_UnitOfWork = IUnitOfWork as UnitOfWork;
}
return _UnitOfWork;
}
}
private MainMenuPages _currentPage;
public MainMenuPages CurrentPage
{
get
{
return _currentPage;
}
set
{
_currentPage = value;
}
}
protected string GetCurrentPageStyle(string pageName)
{
if (CurrentPage.ToString() == pageName)
{
return "active-main-li";
}
else
{
return "";
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
return;
}
}
}
}
我能得到驗證碼出現在形式,而是試圖驗證驗證碼是造成問題。該指令建議輸入以下代碼
if (ctrlGoogleReCaptcha.Validate())
{
//submit form success
lblStatus.Text = "Success";
}
else
{
//captcha challenge failed
lblStatus.Text = "Captcha Failed!! Please try again!!";
}
但是我的代碼不喜歡ctrlGoogleReCaptcha.Validate()
方法。它表示該名稱在當前上下文中不存在。我有沒有通過runat="server"
發送這個?我不確定它爲什麼沒有找到它。