ReCaptcha V2 C# .Net 4.5 fwk

Hello all, I am trying to use ReCaptchaV2 on my web form, and I have having ... issues.

1. I went to the Google page. and got my site key, secret key, and all the html snip-its, that the google.come/recaptcha page provides you.

2. I also went and grabbed the Newtonsoft.Json library and attached that to my project.

3. Finding a decent example online I crated a recapture class to validate the completed recaptca.... and THIS is where my problems arose.

a. The recaptcha works fine. It does select the I am not a robot Check Box... HOWEVER when trying to verify it with a download string I get an  exception error {Unable to connect to the remote server}.


Both sections of Code are underneath


// This is the HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DCaptaProgram.aspx.cs" Inherits="Websiteforservice.DCaptaProgram" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
   <form id="form1" runat="server" defaultbutton="btnLogin" autocomplete="off">
    <div class="error_mass">
    </div>
    <div id="login-box">
        <div class="box-ineer">
            <h1>
               Recaptcha Test
            </h1>          
            </div>
            <div class="frm_row">
                <div class="clear">
                </div>
            </div>         
          <div class="g-recaptcha" data-sitekey="6LfuuQkTAAAAAD-iznE-6TcTJXjTvi4wjFGq8OxX"></div>     
            <div class="login-b">
                <span class="button-l">
                    <asp:Button ID="btnLogin" runat="server" Text="Check Recaptcha" OnClick="btnLogin_Click"  TabIndex ="4"/>
                </span>
                    <div class="clear"> </div>
            </div>
             <div class="cls"></div>
        </div>       
    </div>
    </form>
        <asp:Label ID="lblmsg" runat="server" Text="Label"></asp:Label>

Open in new window


//This is the code behind for the page
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;

namespace Websiteforservice
{
    public partial class DCaptaProgram : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            NewGetter();}
    public class ReCaptchaClass
        {
            public static string Validate(string EncodedResponse)
            {
                var client = new System.Net.WebClient();

                string PrivateKey = "6LfuuQkTAAAAABk8fVWdron_g6fsbfpPXb_1yFHP";

                var GoogleReply = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", PrivateKey, EncodedResponse));

                var captchaResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<ReCaptchaClass>(GoogleReply);

                return captchaResponse.Success;
            }

            [JsonProperty("success")]
            public string Success
            {
                get { return m_Success; }
                set { m_Success = value; }
            }

            private string m_Success;
            [JsonProperty("error-codes")]
            public List<string> ErrorCodes
            {
                get { return m_ErrorCodes; }
                set { m_ErrorCodes = value; }
            }


            private List<string> m_ErrorCodes;
        }

        public void NewGetter()
        {
            string EncodedResponse = Request.Form["g-Recaptcha-Response"];
            bool IsCaptchaValid = (ReCaptchaClass.Validate(EncodedResponse) == "True" ? true : false);

            if (IsCaptchaValid)
            {
                  lblmsg.Text = "Valid Recaptcha2";
                lblmsg.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                lblmsg.Text = "Try Again";
                lblmsg.ForeColor = System.Drawing.Color.Red;
            
            }
        }

Open in new window

HawaiiDragonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
I don't know anything (useful) about your ASP.NET code.  All of my reCaptcha experience has been with PHP and javascript.
HawaiiDragonAuthor Commented:
This is the error I am receiving:  No connection could be made because the target machine actively refused it 74.125.226.116:443
Dave BaldwinFixer of ProblemsCommented:
You are probably trying to do this from a non-public server.  The reCaptcha site does not respond to a server on a private LAN.  It must be accessed from the public server on the internet.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HawaiiDragonAuthor Commented:
Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.