在ASP.NET中实现验证码验证码、ASP、NET

2023-09-04 01:15:53 作者:△_你给的假温柔

我想在我的ASP.NET code插入验证码。基本上,在 lbt_proceed_click()的方法,我想浏览器中使用,以进入下一个页面的Response.Redirect(富)只有当输入了验证码是否正确。

我搜查,但没有找到解决的办法,尤其是因为我没有使用表单发送数据,而是直接写入到数据库,然后使用移动到下一个页面的Response.Redirect( )

解决方案 进入验证码网站并注册的唯一密钥 在下载验证码.NET库 创建并保存你的公钥和私钥安全 在该网站,我们将引用添加到库/斌/发行/ Recaptcha.dll

@Page指令后,插入以下code:

 <%@注册标签preFIX =验证码命名空间=验证码集结号=验证码%>
 

在asp.net标记添加控件:

 <验证码:RecaptchaControl

        ID =验证码

        =服务器

        公钥=你自己的公钥这里

        PrivateKey =你自己的隐私。这里的关键

   />
 
ASP.NET实现验证码

添加按钮和标签到表单中

在隐藏文件code添加下面的按钮点击的方法(btnSubmit_Click)

 如果(Page.IsValid)
{
    lblResult.Text =你猜对了! //或使用的Response.Redirect(富);
}
     其他
{
    lblResult.Text =不正确的;
}
 

测试您的主页!

I am trying to insert a captcha in my ASP.NET code. Basically, in the lbt_proceed_click() method, I want the browser to proceed to the next page using Response.Redirect("foo") only if the captcha entered is correct.

I searched, but could not find a solution, especially since I am not using a form to send data, but writing to a database directly, and then moving to the next page using Response.Redirect().

解决方案

go to the reCAPTCHA site and register for a unique key Download reCAPTCHA .NET Library Create and Save your Public and Private keys safely In the website we add a reference to library/bin/Release/Recaptcha.dll

after the @Page directive, insert the following code:

<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha"%>

add control in asp.net tag:

        <recaptcha:RecaptchaControl

        ID="recaptcha"

        runat="server"

        PublicKey="Your very own public key here"

        PrivateKey="Your very own privat key here"

   />

add button and label to your form

add the following button click method(btnSubmit_Click) in code behind file :

if (Page.IsValid)
{   
    lblResult.Text = "You Got It!"; // Or Use Response.redirect("foo");
}
     else
{
    lblResult.Text = "Incorrect";
}

Test your Page!