在ASP.NET中实现验证码 [英] Implementing reCaptcha in ASP.NET

查看:208
本文介绍了在ASP.NET中实现验证码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

解决方案
  1. 进入验证码网站并注册的唯一密钥
  2. 在下载验证码.NET库
  3. 创建并保存你的公钥和私钥安全
  4. 在该网站,我们将引用添加到库/斌/发行/ Recaptcha.dll
  5. @Page指令后,插入以下code:

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

  6. 在asp.net标记添加控件:

     <验证码:RecaptchaControl
    
            ID =验证码
    
            =服务器
    
            公钥=你自己的公钥这里
    
            PrivateKey =你自己的隐私。这里的关键
    
       />
     

  7. 添加按钮和标签到表单中

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

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

  9. 测试您的主页!

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().

解决方案

  1. go to the reCAPTCHA site and register for a unique key
  2. Download reCAPTCHA .NET Library
  3. Create and Save your Public and Private keys safely
  4. In the website we add a reference to library/bin/Release/Recaptcha.dll
  5. after the @Page directive, insert the following code:

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

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

  7. add button and label to your form

  8. 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";
    }
    

  9. Test your Page!

这篇关于在ASP.NET中实现验证码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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