reCAPTCHA with C#.NET

2,257 views
Skip to first unread message

Gayle Laakmann

unread,
May 25, 2007, 11:58:03 AM5/25/07
to reCAPTCHA
I have a web app that is written with C#.NET. Do you have any
examples on how to use it from C#.NET (or VB.NET is fine)?

reCAPTCHA Support

unread,
May 25, 2007, 12:58:47 PM5/25/07
to reca...@googlegroups.com
We're hoping to have a C# plugin in the future. It'd be great if the community would develop one, somebody already did a Ruby plugin:

http://www.loonsoft.com/recaptcha/

On 5/25/07, Gayle Laakmann <gay...@gmail.com> wrote:

I have a web app that is written with C#.NET.  Do you have any
examples on how to use it from C#.NET (or VB.NET is fine)?


--
reCAPTCHA: stop spam, read books
http://recaptcha.net

Hunter Daley

unread,
Jun 3, 2007, 12:33:36 AM6/3/07
to reCAPTCHA
I'm going to try to figure this out in C# for http://www.uberhuge.com
registration if I have some free time. I'll post my solution in this
thread as well as on my site:
http://www.hunterconcepts.com

On May 25, 12:58 pm, "reCAPTCHA Support" <supp...@recaptcha.net>
wrote:

Hunter Daley

unread,
Jun 3, 2007, 12:44:01 AM6/3/07
to reCAPTCHA
Hopefully when I'm all done I'll have a server control that people can
just drag and drop into their .NET solution and be done with it.

Keep you posted.

On Jun 3, 12:33 am, Hunter Daley <hunter.da...@gmail.com> wrote:
> I'm going to try to figure this out in C# forhttp://www.uberhuge.com


> registration if I have some free time. I'll post my solution in this
> thread as well as on my site:http://www.hunterconcepts.com
>
> On May 25, 12:58 pm, "reCAPTCHA Support" <supp...@recaptcha.net>
> wrote:
>
>
>
> > We're hoping to have a C# plugin in the future. It'd be great if the
> > community would develop one, somebody already did a Ruby plugin:
>
> >http://www.loonsoft.com/recaptcha/
>
> > On 5/25/07, Gayle Laakmann <gay...@gmail.com> wrote:
>
> > > I have a web app that is written with C#.NET. Do you have any

> > > examples on how to use it from C#.NET(or VB.NETis fine)?
>
> > --
> > reCAPTCHA: stop spam, read bookshttp://recaptcha.net- Hide quoted text -
>
> - Show quoted text -

reCAPTCHA Support

unread,
Jun 3, 2007, 12:53:10 AM6/3/07
to reca...@googlegroups.com, Joseph Hill
Hey,

Just FYI, Joseph Hill (CC'd) is working on a .NET plugin. He's pretty close to finished, so you two might want to work together.

-Ben

jmh...@gmail.com

unread,
Jun 3, 2007, 1:06:46 AM6/3/07
to reCAPTCHA
All,
I got an early version of this working today. I need to clean it up a
bit more to get it ready for real public consumption; however, I'll
try to get the source up somewhere ASAP so that you can give it a
spin.
I've implemented it as a Validator so if you'd like to use the control
in a different manner, you may find the code useful as the basis for a
different kind of control.

Joseph Hill

On Jun 2, 11:53 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> Hey,
>
> Just FYI, Joseph Hill (CC'd) is working on a .NET plugin. He's pretty close
> to finished, so you two might want to work together.
>
> -Ben
>

> On 6/3/07, Hunter Daley <hunter.da...@gmail.com> wrote:
>
>
>
>
>
> > Hopefully when I'm all done I'll have a server control that people can
> > just drag and drop into their .NET solution and be done with it.
>
> > Keep you posted.
>
> > On Jun 3, 12:33 am, Hunter Daley <hunter.da...@gmail.com> wrote:
> > > I'm going to try to figure this out in C# forhttp://www.uberhuge.com
> > > registration if I have some free time. I'll post my solution in this
> > > thread as well as on my site:http://www.hunterconcepts.com
>
> > > On May 25, 12:58 pm, "reCAPTCHA Support" <supp...@recaptcha.net>
> > > wrote:
>
> > > > We're hoping to have a C# plugin in the future. It'd be great if the
> > > > community would develop one, somebody already did a Ruby plugin:
>
> > > >http://www.loonsoft.com/recaptcha/
>
> > > > On 5/25/07, Gayle Laakmann <gay...@gmail.com> wrote:
>
> > > > > I have a web app that is written with C#.NET. Do you have any
> > > > > examples on how to use it from C#.NET(or VB.NETis fine)?
>
> > > > --

> > > > reCAPTCHA: stop spam, read bookshttp://recaptcha.net-Hide quoted text


> > -
>
> > > - Show quoted text -
>

Hunter Daley

unread,
Jun 4, 2007, 8:50:51 AM6/4/07
to reCAPTCHA
Ok, sounds good. I was going to implement a light .NET Server Control
with AJAX (using Sarissa and/or jQuery), but there's no use
reinventing the wheel. Let me know when you get some source up and
I'll check it out and see what I can use.

> > > > > reCAPTCHA: stop spam, read bookshttp://recaptcha.net-Hidequoted text


> > > -
>
> > > > - Show quoted text -
>
> > --

> > reCAPTCHA: stop spam, read bookshttp://recaptcha.net- Hide quoted text -

jmh...@gmail.com

unread,
Jun 5, 2007, 12:53:16 AM6/5/07
to reCAPTCHA
I've committed a reCAPTCHA validator for ASP.NET into the dotnet
directory, including source for a 2003 project, a 1.1 compiled
assembly, and a sample aspx page to test against.

The license is MIT/X11, please feel free to borrow whatever portion of
the code you would like if you would like to produce different
implementations.

Questions or feedback would be greatly appreciated.

Thanks,
Joseph Hill

> > > reCAPTCHA: stop spam, read bookshttp://recaptcha.net-Hide quoted text -

michael...@gmail.com

unread,
Jun 13, 2007, 6:42:29 AM6/13/07
to reCAPTCHA
Joseph,

Where is this dotnet directory at? I see no such thing in this forum.
Do you have a link?

> > > > reCAPTCHA: stop spam, read bookshttp://recaptcha.net-Hidequoted text -

michael...@gmail.com

unread,
Jun 13, 2007, 6:44:34 AM6/13/07
to reCAPTCHA
Joseph,

Nevermind. I found it if I go to google code for everyone else:

http://recaptcha.googlecode.com/svn/trunk/recaptcha-plugins/dotnet/


On Jun 5, 12:53 am, "jmh...@gmail.com" <jmh...@gmail.com> wrote:

> > > > reCAPTCHA: stop spam, read bookshttp://recaptcha.net-Hidequoted text -

RCicotte

unread,
Jun 18, 2007, 8:42:56 AM6/18/07
to reCAPTCHA
John,

Thanks for the sample code for a C# implemntation of reCAPTCHA. I've
used it to create a reCAPTCHA.dll for implementing it in Community
Server. I'm using VS2005 and .NET 2.0. I'll be creating a component
to drop into any VS2005 app in the next week or so (as time permits)
and also a CS (Community Server) module that can be referenced
directly in a CS implementation.

Please check out my current CS implementation of reCAPTCHA at
http://www.grillerinthemist.com

Thanks

On Jun 5, 12:53 am, "jmh...@gmail.com" <jmh...@gmail.com> wrote:

> I've committed a reCAPTCHA validator for ASP.NETinto the dotnet


> directory, including source for a 2003 project, a 1.1 compiled
> assembly, and a sample aspx page to test against.
>
> The license is MIT/X11, please feel free to borrow whatever portion of
> the code you would like if you would like to produce different
> implementations.
>
> Questions or feedback would be greatly appreciated.
>
> Thanks,
> Joseph Hill
>
> On Jun 4, 7:50 am, Hunter Daley <hunter.da...@gmail.com> wrote:
>
>
>

> > Ok, sounds good. I was going to implement a light .NETServer Control


> > with AJAX (using Sarissa and/or jQuery), but there's no use
> > reinventing the wheel. Let me know when you get some source up and
> > I'll check it out and see what I can use.
>
> > On Jun 3, 1:06 am, "jmh...@gmail.com" <jmh...@gmail.com> wrote:
>
> > > All,
> > > I got an early version of this working today. I need to clean it up a
> > > bit more to get it ready for real public consumption; however, I'll
> > > try to get the source up somewhere ASAP so that you can give it a
> > > spin.
> > > I've implemented it as a Validator so if you'd like to use the control
> > > in a different manner, you may find the code useful as the basis for a
> > > different kind of control.
>
> > > Joseph Hill
>
> > > On Jun 2, 11:53 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
>
> > > > Hey,
>

> > > > Just FYI, Joseph Hill (CC'd) is working on a .NETplugin. He's pretty close


> > > > to finished, so you two might want to work together.
>
> > > > -Ben
>
> > > > On 6/3/07, Hunter Daley <hunter.da...@gmail.com> wrote:
>
> > > > > Hopefully when I'm all done I'll have a server control that people can

> > > > > just drag and drop into their .NETsolution and be done with it.


>
> > > > > Keep you posted.
>
> > > > > On Jun 3, 12:33 am, Hunter Daley <hunter.da...@gmail.com> wrote:
> > > > > > I'm going to try to figure this out in C# forhttp://www.uberhuge.com
> > > > > > registration if I have some free time. I'll post my solution in this
> > > > > > thread as well as on my site:http://www.hunterconcepts.com
>
> > > > > > On May 25, 12:58 pm, "reCAPTCHA Support" <supp...@recaptcha.net>
> > > > > > wrote:
>
> > > > > > > We're hoping to have a C# plugin in the future. It'd be great if the
> > > > > > > community would develop one, somebody already did a Ruby plugin:
>
> > > > > > >http://www.loonsoft.com/recaptcha/
>
> > > > > > > On 5/25/07, Gayle Laakmann <gay...@gmail.com> wrote:
>
> > > > > > > > I have a web app that is written with C#.NET. Do you have any
> > > > > > > > examples on how to use it from C#.NET(or VB.NETis fine)?
>
> > > > > > > --
> > > > > > > reCAPTCHA: stop spam, read bookshttp://recaptcha.net-Hidequotedtext
> > > > > -
>
> > > > > > - Show quoted text -
>
> > > > --

> > > > reCAPTCHA: stop spam, read bookshttp://recaptcha.net-Hidequoted text -
>
> > > - Show quoted text -- Hide quoted text -

RCicotte

unread,
Jun 18, 2007, 8:46:31 AM6/18/07
to reCAPTCHA
Sorry for the incorrect name. I referred to you as John. I see now
that it's Joseph. I think I need another cup of coffee :).


On Jun 18, 8:42 am, RCicotte <ron.cico...@gmail.com> wrote:
> John,
>
> Thanks for the sample code for a C# implemntation of reCAPTCHA. I've
> used it to create a reCAPTCHA.dll for implementing it in Community

> Server. I'm using VS2005 and .NET2.0. I'll be creating a component


> to drop into any VS2005 app in the next week or so (as time permits)
> and also a CS (Community Server) module that can be referenced
> directly in a CS implementation.
>

> Please check out my current CS implementation of reCAPTCHA athttp://www.grillerinthemist.com

reCAPTCHA Support

unread,
Jun 18, 2007, 1:14:34 PM6/18/07
to reca...@googlegroups.com
Hello,

The placement of reCAPTCHA on a different page in your site is a bit worrying. This often leads to an attack where a spammer can use the same captcha solution multiple times. Is it possible to have a plugin that puts the CAPTCHA on the reigsitration form, like when signing up for an account on Google or Yahoo?


Adrian Godong

unread,
Jun 19, 2007, 10:38:05 AM6/19/07
to reca...@googlegroups.com
Hi RCicotte,

I already have a reCAPTCHA control you can drag and drop to, drop me a line
if you'd like.

I've tried Joseph's code, but it has some error (I think it's because I'm
using it in netfx20), so I've decided to write a quick new one. It's not
complete yet, and it's not a validator control (since I don't know how to
create one), but it just works. I'll also try checking that in to Google
Code tomorrow morning (GMT+7).

jmh...@gmail.com

unread,
Jun 20, 2007, 10:02:41 AM6/20/07
to reCAPTCHA
Hi RCicotte,
That's great. I'm glad someone has taken care of CS. I know a lot of
those deployments would be a good candidate for reCAPTCHA. I'd be
really interested in seeing your CS module if you can send it to me.

Hi Adrian,
I think that's great, also. I think we needed a non-validator
implementation anyways. If you can forward me the source for that,
I'd appreciate it.
Also, can you tell me specifically what errors you got with the
validator? I tested against 1.1, 2.0, and Mono. I'll probably commit
a 2.0 build in the next few days anyways, just to make sure that all
of the 2.0 features are exposed in the control.

All,
I'm starting to put together docs for a .NET page for the reCAPTCHA
site. If either of you have anything to add to that, it would be
greatly appreciated. I can forward you the docs as soon as I have
them a little more fleshed out if you are interested.

Thanks,
Joseph


On Jun 19, 9:38 am, "Adrian Godong" <adrian.god...@gmail.com> wrote:
> Hi RCicotte,
>
> I already have a reCAPTCHA control you can drag and drop to, drop me a line
> if you'd like.
>
> I've tried Joseph's code, but it has some error (I think it's because I'm
> using it in netfx20), so I've decided to write a quick new one. It's not
> complete yet, and it's not a validator control (since I don't know how to
> create one), but it just works. I'll also try checking that in to Google
> Code tomorrow morning (GMT+7).
>
> -----Original Message-----
> From: reca...@googlegroups.com [mailto:reca...@googlegroups.com] On
>
> Behalf Of RCicotte
> Sent: 18 Juni 2007 19:43
> To: reCAPTCHA
> Subject: Re: reCAPTCHA with C#.NET
>
> John,
>
> Thanks for the sample code for a C# implemntation of reCAPTCHA. I've
> used it to create a reCAPTCHA.dll for implementing it in Community
> Server. I'm using VS2005 and .NET 2.0. I'll be creating a component
> to drop into any VS2005 app in the next week or so (as time permits)
> and also a CS (Community Server) module that can be referenced
> directly in a CS implementation.
>

> Please check out my current CS implementation of reCAPTCHA athttp://www.grillerinthemist.com

> > > > > reCAPTCHA: stop spam, read bookshttp://recaptcha.net-Hidequotedtext
> -
>

RCicotte

unread,
Jun 20, 2007, 5:59:26 PM6/20/07
to reCAPTCHA
Joseph,

I think I spoke too soon :( . My reCAPTCHA implementation is not
quite complete. It turns out that it worked fine until I updated my
CS implementation to SP3. Telllegent in their infinite wisdom decided
to add a page_load and validation code to the CreateNewUser.ascx
control which is where I inserted my code. Now I have to figure out
how to get it working in the new event stream. It seems to validate
just fine but then I get a ReCAPTCHA API error when the page is
validated by the new control for the new user form text. The control
is apparently still in the view state. I need to unload the module
after the successfule ReCAPTCHA return so that when the page is
resubmitted for the form it will not resubmit the call to the
ReCAPTCHA web service.

I'm very close but not quite there yet. I'd love to see any new code
you come up with. I am using .NET 2.0 and VS 2005.

Thanks,

-ron cicotte

On Jun 20, 10:02 am, "jmh...@gmail.com" <jmh...@gmail.com> wrote:
> Hi RCicotte,
> That's great. I'm glad someone has taken care of CS. I know a lot of

> those deployments would be a good candidate forreCAPTCHA. I'd be


> really interested in seeing your CS module if you can send it to me.
>
> Hi Adrian,
> I think that's great, also. I think we needed a non-validator
> implementation anyways. If you can forward me the source for that,
> I'd appreciate it.
> Also, can you tell me specifically what errors you got with the
> validator? I tested against 1.1, 2.0, and Mono. I'll probably commit
> a 2.0 build in the next few days anyways, just to make sure that all
> of the 2.0 features are exposed in the control.
>
> All,
> I'm starting to put together docs for a .NET page for thereCAPTCHA
> site. If either of you have anything to add to that, it would be
> greatly appreciated. I can forward you the docs as soon as I have
> them a little more fleshed out if you are interested.
>
> Thanks,
> Joseph
>
> On Jun 19, 9:38 am, "Adrian Godong" <adrian.god...@gmail.com> wrote:
>
>
>
> > Hi RCicotte,
>

> > I already have areCAPTCHAcontrol you can drag and drop to, drop me a line


> > if you'd like.
>
> > I've tried Joseph's code, but it has some error (I think it's because I'm
> > using it in netfx20), so I've decided to write a quick new one. It's not
> > complete yet, and it's not a validator control (since I don't know how to
> > create one), but it just works. I'll also try checking that in to Google
> > Code tomorrow morning (GMT+7).
>
> > -----Original Message-----
> > From:reca...@googlegroups.com [mailto:reca...@googlegroups.com] On
>
> > Behalf Of RCicotte
> > Sent: 18 Juni 2007 19:43
> > To:reCAPTCHA

> > Subject: Re:reCAPTCHAwith C#.NET
>
> > John,
>
> > Thanks for the sample code for a C# implemntation ofreCAPTCHA. I've
> > used it to create areCAPTCHA.dll for implementing it in Community


> > Server. I'm using VS2005 and .NET 2.0. I'll be creating a component
> > to drop into any VS2005 app in the next week or so (as time permits)
> > and also a CS (Community Server) module that can be referenced
> > directly in a CS implementation.
>

> > Please check out my current CS implementation ofreCAPTCHAathttp://www.grillerinthemist.com


>
> > Thanks
>
> > On Jun 5, 12:53 am, "jmh...@gmail.com" <jmh...@gmail.com> wrote:

> > > I've committed areCAPTCHAvalidator for ASP.NETinto the dotnet


> > > directory, including source for a 2003 project, a 1.1 compiled
> > > assembly, and a sample aspx page to test against.
>
> > > The license is MIT/X11, please feel free to borrow whatever portion of
> > > the code you would like if you would like to produce different
> > > implementations.
>
> > > Questions or feedback would be greatly appreciated.
>
> > > Thanks,
> > > Joseph Hill
>
> > > On Jun 4, 7:50 am, Hunter Daley <hunter.da...@gmail.com> wrote:
>
> > > > Ok, sounds good. I was going to implement a light .NETServer Control
> > > > with AJAX (using Sarissa and/or jQuery), but there's no use
> > > > reinventing the wheel. Let me know when you get some source up and
> > > > I'll check it out and see what I can use.
>
> > > > On Jun 3, 1:06 am, "jmh...@gmail.com" <jmh...@gmail.com> wrote:
>
> > > > > All,
> > > > > I got an early version of this working today. I need to clean it up a
> > > > > bit more to get it ready for real public consumption; however, I'll
> > > > > try to get the source up somewhere ASAP so that you can give it a
> > > > > spin.
> > > > > I've implemented it as a Validator so if you'd like to use the control
> > > > > in a different manner, you may find the code useful as the basis for a
> > > > > different kind of control.
>
> > > > > Joseph Hill
>

> > > > > On Jun 2, 11:53 pm, "reCAPTCHASupport" <supp...@recaptcha.net> wrote:
>
> > > > > > Hey,
>
> > > > > > Just FYI, Joseph Hill (CC'd) is working on a .NETplugin. He's pretty
> > close
> > > > > > to finished, so you two might want to work together.
>
> > > > > > -Ben
>
> > > > > > On 6/3/07, Hunter Daley <hunter.da...@gmail.com> wrote:
>
> > > > > > > Hopefully when I'm all done I'll have a server control that people
> > can
> > > > > > > just drag and drop into their .NETsolution and be done with it.
>
> > > > > > > Keep you posted.
>
> > > > > > > On Jun 3, 12:33 am, Hunter Daley <hunter.da...@gmail.com> wrote:
> > > > > > > > I'm going to try to figure this out in C#
> > forhttp://www.uberhuge.com
> > > > > > > > registration if I have some free time. I'll post my solution in
> > this
> > > > > > > > thread as well as on my site:http://www.hunterconcepts.com
>

> > > > > > > > On May 25, 12:58 pm, "reCAPTCHASupport" <supp...@recaptcha.net>

reCAPTCHA Support

unread,
Jun 20, 2007, 6:13:06 PM6/20/07
to reca...@googlegroups.com
Hello,

On 6/20/07, RCicotte <ron.c...@gmail.com> wrote:
 The control
is apparently still in the view state.  I need to unload the module
after the successfule ReCAPTCHA return so that when the page is
resubmitted for the form it will not resubmit the call to the
ReCAPTCHA web service.

Be *really* careful about this. You don't want to create a situation such that a spammer can solve one captcha and use the solution multiple times.  The reCAPTCHA web service explicitly allows one solution per CAPTCHA. If you do some sort of caching of correct solutions, you'll need to handle this situation on your own.

-Ben

Adrian Godong

unread,
Jun 20, 2007, 10:12:39 PM6/20/07
to reca...@googlegroups.com

Well, I don't know any CS, but in my implementation you'll need to call ValidateCaptcha() manually (that's one reason to use/not use Validator control).

You can call the method after all other control are valid. Since you'll need to call external service you'll want to make sure it's the only one thing left for validation, otherwise you'll call external service every single time (IMO, kind of waste of resources).

To contrast in my control, I've called Validate() in Page_Load for convenience since validation is mostly client-side (using validator control), so everything's pretty much done if there's a postback.

<code snip>

protected void Page_Load(object sender, EventArgs e)
{

if (Page.IsPostBack) this.Validate();

StringBuilder builder = new StringBuilder();

//create scripts here, use the StringBuilder for efficient string creation

this.ReCaptchaLiteral.Text = builder.ToString();
}

</code snip>


 

Ronald Cicotte

unread,
Jun 20, 2007, 10:49:48 PM6/20/07
to reca...@googlegroups.com

Adrian,

 

Community Server uses many skins and templates which makes it very difficult to follow the event stream.  It turns out that I was able to solve my problem in a fairly simple way by inserting the ReCAPTCHA validator in the proper place and letting the existing CS submit button do the rest. 

 

I was trying to make it a two step process by showing and hiding different sections of the page but I couldn’t find an easy way to disable the ReCAPTCHA validation on the second submit.  I’m sure I could do it with your control since you call the validation separately.  I was going to create the control and as you did but decided to put that aside for now and use Joseph’s Validator since it works and I don’t have any more time to play at the moment.

 

I would really like to see your code though.  I’m new to control development and don’t yet have a good understanding of how you wire these things up.  I’m really a backend guy (data modeling and stored procs).

 

Thanks,

 

-ron

 


From: reca...@googlegroups.com [mailto:reca...@googlegroups.com] On Behalf Of Adrian Godong
Sent: Wednesday, June 20, 2007 10:13 PM
To: reca...@googlegroups.com
Subject: Re: reCAPTCHA with C#.NET

 

Well, I don't know any CS, but in my implementation you'll need to call ValidateCaptcha() manually (that's one reason to use/not use Validator control).

Adrian Godong

unread,
Jun 21, 2007, 11:05:11 AM6/21/07
to reca...@googlegroups.com

I’m a library guy, too. Now if only I can post this code somewhere (prefers Google Code, but need admin approval).

Ronald Cicotte

unread,
Jun 21, 2007, 12:34:11 PM6/21/07
to reca...@googlegroups.com

You could post it on my CS website here: http://cs.summerstreet.com . You’ll have to join (Using my new ReCaptcha) validator.  After you have joined you will be logged in automatically.  Then you can:

 

  1. Select Downloads from the main menu.
  2. Select Trusted | Development form the Sidebar Tree Menu
  3. Select Upload
  4. If you select Specify File/URL.  A dialog will open to allow you to browse to select the file or you can just type the path in if you’d rather.
  5. If you selected the browse option select Save.  Only documents with the following extensions are allowed:
    1. .doc
    2. .txt
    3. .zip
  6. Enter a brief title for the upload in the Name field (required)
  7. Enter a longer description of what the file contains in the Description field
  8. You can use the Tags field to organize the file(s). 
  9. Click the Save button.

 

You can then use a  link to the downloads page to tell others where the file(s) are posted.  You need to be logged in to download these files but I can also create a public area where anyone can download them.

 

CS is really a full featured app with areas for blogs, photos, file sharing, forums and rss feeds.  There’s a lot more in the commercial version but they’re beginning to dumb it down for the free version and restricting the license.  That’s one reason why I have not upgraded to the latest version.  You have to pay to have more than one site and not allowed to use it for commercial (i.e. my Summer Street Systems site).  I have 6 other sites where I use this software.

 

Let me know if you run into any problems posting it.  I will start a ReCaptcha forum this weekend. I’m getting ready for an interview with a potential client so I can’t do it right now.  …but you can create one by starting a new topic if you like.


lang=IN>


reCAPTCHA Support

unread,
Jun 21, 2007, 2:44:05 PM6/21/07
to reca...@googlegroups.com
Added you as a member on the Google Code project

Gayle Laakmann

unread,
Jun 23, 2007, 1:43:26 PM6/23/07
to reCAPTCHA
I tried Joseph's code at http://recaptcha.googlecode.com/svn/trunk/recaptcha-plugins/dotnet/.
I'm using ASP.NET 1.1.

I have a few questions:

1) It has a parameter called "ControlToValidate" that needs to be
wired up to a TextBox. What does that textbox aactually do - or what
is it supposed to do? It seems to just sit there, doing nothing but
taking up space.

2) When the control loads, it says "recaptcha API error" and the help
link points to "invalid-request-cookie: The challenge parameter of the
verify script was incorrect." It still seems to work fine - but I
don't want users to see this error. How can I fix that? It appears
even when I use the exact example on the page.

3) The example source given provides the following user experience:
user clicks submit -> recaptcha appears -> user types in captcha texts
-> clicks submit again. It seems strange that you would want the
captcha to appear only after the user has already clicked submit, and
then make the user click submit again. I'd like the captcha to show
up with the page load. To do this, I moved Page.Validate() up to the
Page Load code (see http://recaptcha.googlecode.com/svn/trunk/recaptcha-plugins/dotnet/sample/Default.aspx
for the original code). It works, but is this the right way to do it?

Thanks!
Gayle

On Jun 13, 3:44 am, "michael.rumi...@gmail.com"

> > > > > > > I'm going to try to figure this out inC#forhttp://www.uberhuge.com


> > > > > > > registration if I have some free time. I'll post my solution in this
> > > > > > > thread as well as on my site:http://www.hunterconcepts.com
>
> > > > > > > On May 25, 12:58 pm, "reCAPTCHA Support" <supp...@recaptcha.net>
> > > > > > > wrote:
>
> > > > > > > > We're hoping to have a C# plugin in the future. It'd be great if the
> > > > > > > > community would develop one, somebody already did a Ruby plugin:
>
> > > > > > > >http://www.loonsoft.com/recaptcha/
>
> > > > > > > > On 5/25/07, Gayle Laakmann <gay...@gmail.com> wrote:
>

> > > > > > > > > I have a web app that is written withC#.NET. Do you have any
> > > > > > > > > examples on how to use it fromC#.NET(or VB.NETis fine)?

Adrian Godong

unread,
Jun 23, 2007, 9:34:33 PM6/23/07
to reca...@googlegroups.com
OK, thanks, I'll try to upload ASAP.

Steve Marchessault

unread,
Jun 28, 2007, 9:04:11 AM6/28/07
to reCAPTCHA
I noticed when using the above implementation of reCAPTCHA in C# that
the control displays correctly on load in IE but in all other browsers
(FireFox, Safari, etc) it does not display on load and displays with
an error on postback. I was looking at how the control renders itself
and noticed the following code:

<span id="RecaptchaValidator1" controltovalidate="RecaptchaValidator1"
style="color:Red;visibility:hidden;"></span>

The style tag has the visibility property set to hidden which IE must
be ignoring but other browsers are using. I can't find in the source
code where this is getting set. Does anyone else experience the same
problem?

Adrian Godong

unread,
Jun 28, 2007, 9:33:27 AM6/28/07
to reca...@googlegroups.com
Could you please try the latest version found in
http://recaptcha.googlecode.com/svn?

The attached code does not work as expected.

Thanks,

----- Original Message -----
From: "Steve Marchessault" <caretech...@gmail.com>
To: "reCAPTCHA" <reca...@googlegroups.com>
Sent: Thursday, June 28, 2007 8:04 PM
Subject: Re: reCAPTCHA with C#.NET


>

Steve Marchessault

unread,
Jun 28, 2007, 9:36:32 AM6/28/07
to reCAPTCHA
I did try the newest version this morning at:

http://recaptcha.googlecode.com/svn/trunk/recaptcha-plugins/dotnet/

Revision 31 and I experience the problem as described.

Adrian Godong

unread,
Jun 28, 2007, 10:28:50 AM6/28/07
to reca...@googlegroups.com
Did you try the Recaptcha or Recaptcha2 folder?

What version of .NET are you running?

----- Original Message -----
From: "Steve Marchessault" <caretech...@gmail.com>
To: "reCAPTCHA" <reca...@googlegroups.com>
Sent: Thursday, June 28, 2007 8:36 PM
Subject: Re: reCAPTCHA with C#.NET


>

Steve Marchessault

unread,
Jun 28, 2007, 10:32:32 AM6/28/07
to reCAPTCHA
I didn't grab the source code. I just took the DLL from the bin
folder. Is that not the newest DLL? I am running .NET 1.1.

> > Revision 31 and I experience the problem as described.- Hide quoted text -

Steve Marchessault

unread,
Jun 28, 2007, 1:26:39 PM6/28/07
to reCAPTCHA
Adrian,

It seems that your Recaptcha2 (.NET 2.0) version runs just fine in
Firefox and Safari. The Recaptcha (.NET 1.1) does not function in
Firefox and Safari well. Would it be possible to correct that as you
did in .NET 2.0 or am I forced to upgrade?

On Jun 28, 10:32 am, Steve Marchessault <caretechsoluti...@gmail.com>
wrote:

> > - Show quoted text -- Hide quoted text -

Adrian Godong

unread,
Jun 28, 2007, 9:40:41 PM6/28/07
to reca...@googlegroups.com
Can you compile it in .NET 1.1? If it's compilable, then you're good to go.
 
If it's not, you will need to compare both projects (Recaptcha and Recaptcha2), and try manually merge them. I don't have VS.NET 2003 or .NET 1.1 SDK so I can't do/test it.
 
Anyway, any good reason you're sticking with v1.1?
 
--
Adrian Godong

Steve Marchessault

unread,
Jun 29, 2007, 8:21:12 AM6/29/07
to reCAPTCHA
Recaptcha2 won't complile in VS 2003. I compiled it in VS 2005 and
when it tries to validate I get a "Object reference not set to an
instance of an object." error. Have you successfully compiled
Recaptcha2?

The website I want to run this on is .NET 1.1. I can run the form as
a virutual app using .NET 2.0 which I tried but I get the error
above. Are you experiencing the same error?

On Jun 28, 9:40 pm, "Adrian Godong" <adrian.god...@gmail.com> wrote:
> Can you compile it in .NET 1.1? If it's compilable, then you're good to go.
>
> If it's not, you will need to compare both projects (Recaptcha and
> Recaptcha2), and try manually merge them. I don't have VS.NET 2003 or .NET
> 1.1 SDK so I can't do/test it.
>
> Anyway, any good reason you're sticking with v1.1?
>

> adrian.god...@gmail.com
> Microsoft MVPhttps://mvp.support.microsoft.com/profile/Adrian- Hide quoted text -

Adrian Godong

unread,
Jun 29, 2007, 12:58:24 PM6/29/07
to reca...@googlegroups.com
Can you give me the stack trace?

I don't know how to run a virtual app, I'm assuming that you have two
different applications in your IIS (that means you're using something like
Win Server) and when you need to use reCAPTCHA you move from the 1.1 app to
2.0 app and then back again? Applications cannot share state, that might
what caused the NullReferenceException.

----- Original Message -----
From: "Steve Marchessault" <caretech...@gmail.com>
To: "reCAPTCHA" <reca...@googlegroups.com>

reCAPTCHA Support

unread,
Jun 29, 2007, 1:17:22 PM6/29/07
to reca...@googlegroups.com
What compile error do you get in 2005? If it doesn't compile in that version, most likely it won't run there.

Question for you .NET folks: how common is .NET 1.1 these days? I've personally lost track of the .NET world a bit (I used to be a developer on the Mono project which develops .NET for Linux).

-Ben

On 6/29/07, Steve Marchessault <caretech...@gmail.com> wrote:

Steve Marchessault

unread,
Jun 29, 2007, 1:35:09 PM6/29/07
to reCAPTCHA
Adrian,

A virtual app allows me to run .NET 1.1 and 2.0 side-by-side. I'm
getting the error in both the virtual app situation and the
standalone .NET 2.0 environment. The stack trace is as follows:

[NullReferenceException: Object reference not set to an instance of an
object.]
Recaptcha.RecaptchaControl.DoValidation() +898
Recaptcha.RecaptchaControl.Validate() +25
System.Web.UI.Page.Validate() +133
System.Web.UI.Page.Validate(String validationGroup) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +81

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5102

reCAPTCHA support,

I do not get a compile error in VS 2005. I get the error when the
reCAPTCHA control tries to validate. This happens with the
"Recaptcha2" project which is .NET 2.0. The only reason I was using
the old .NET 1.1 control was because the application I want to use it
with is old and only can run in .NET 1.1. I can use the .NET 2.0
control with the newer projects I'm working on. So I think the .NET
2.0 would be the ideal one to use for most developers.

On Jun 29, 1:17 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> What compile error do you get in 2005? If it doesn't compile in that
> version, most likely it won't run there.
>
> Question for you .NET folks: how common is .NET 1.1 these days? I've
> personally lost track of the .NET world a bit (I used to be a developer on
> the Mono project which develops .NET for Linux).
>
> -Ben
>

> reCAPTCHA: stop spam, read bookshttp://recaptcha.net- Hide quoted text -

Steve Marchessault

unread,
Jul 2, 2007, 8:37:12 AM7/2/07
to reCAPTCHA
Adrian,

What has changed in revision 32?

On Jun 29, 1:35 pm, Steve Marchessault <caretechsoluti...@gmail.com>
wrote:
> Adrian,
>


> A virtual app allows me to run .NET 1.1 and 2.0 side-by-side. I'm
> getting the error in both the virtual app situation and the
> standalone .NET 2.0 environment. The stack trace is as follows:
>
> [NullReferenceException: Object reference not set to an instance of an
> object.]
> Recaptcha.RecaptchaControl.DoValidation() +898
> Recaptcha.RecaptchaControl.Validate() +25
> System.Web.UI.Page.Validate() +133
> System.Web.UI.Page.Validate(String validationGroup) +105
> System.Web.UI.WebControls.Button.RaisePostBackEvent(String
> eventArgument) +81
>

> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaiseP­ostBackEvent(String

> > reCAPTCHA: stop spam, read bookshttp://recaptcha.net-Hide quoted text -

Adrian Godong

unread,
Jul 2, 2007, 8:17:00 PM7/2/07
to reca...@googlegroups.com
I have notified this in the other thread. There is only one change, private and public key are now configurable through app.config/web.config. No other changes made.

On 7/2/07, Steve Marchessault <caretech...@gmail.com> wrote:

Adrian,

What has changed in revision 32?

On Jun 29, 1:35 pm, Steve Marchessault < caretechsoluti...@gmail.com>
wrote:
> Adrian,
>
> A virtual app allows me to run .NET 1.1 and 2.0 side-by-side.  I'm
> getting the error in both the virtual app situation and the
> standalone .NET 2.0 environment.  The stack trace is as follows:
>
> [NullReferenceException: Object reference not set to an instance of an
> object.]
>    Recaptcha.RecaptchaControl.DoValidation() +898
>     Recaptcha.RecaptchaControl.Validate() +25
>    System.Web.UI.Page.Validate() +133
>    System.Web.UI.Page.Validate(String validationGroup) +105
>    System.Web.UI.WebControls.Button.RaisePostBackEvent(String
> eventArgument) +81
>
> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaiseP-ostBackEvent(String

Steve Marchessault

unread,
Jul 3, 2007, 8:11:41 AM7/3/07
to reCAPTCHA
Adrian,

Do you have a compiled version of your "Recaptcha2" project? I am
unable to get it working successfully. I keep getting the "Object not
set to an instance" error on submit.

On Jul 2, 8:17 pm, "Adrian Godong" <adrian.god...@gmail.com> wrote:
> I have notified this in the other thread. There is only one change, private
> and public key are now configurable through app.config/web.config. No other
> changes made.
>

> > > > reCAPTCHA: stop spam, read bookshttp://recaptcha.net-Hidequoted text

Steve Marchessault

unread,
Jul 3, 2007, 2:27:49 PM7/3/07
to reCAPTCHA
Ok, I successfully compiled the "Recaptcha2" project and no longer get
an "Object not set to an instance" error on submit. However, I now
get a reCAPTCHA API error ("error-recaptcha-not-reachable"). I'm
assuming that when it tries to read the response from the server
somehow it fails and enters your catch statement that throws the
"error-recaptcha-not-reachable" error. Are you experiencing the same
error?

On Jul 3, 8:11 am, Steve Marchessault <caretechsoluti...@gmail.com>

> > Microsoft MVPhttps://mvp.support.microsoft.com/profile/Adrian- Hide quoted text -

Adrian Godong

unread,
Jul 3, 2007, 8:14:34 PM7/3/07
to reca...@googlegroups.com
Well, definitely not happening to me. :D

Can you create a small app just to test connectivity with reCAPTCHA
servers? Say, create an aspx page and then on page load execute a
WebRequest.GetResponse() to reCAPTCHA server URI and see what you get.

I still think this is a firewall problem. Have you checked your
firewall? (port 80 outbound, not inbound)

Marc Miles

unread,
Jul 3, 2007, 11:56:15 PM7/3/07
to reCAPTCHA
Well, Im getting the problem, and I dont think its my firewall, its
the api URI specifically, see below (latest code from your site and
c#.net 2.0)

For the URL below using http://api.recaptcha.net returns a 404 not
found, but using http://www.google.com and http://api-verify.recaptcha.net/verify
it returns valid http headers?

Very strange, please advise.


protected void Page_Load(object sender, EventArgs e)
{

WebRequest request = WebRequest.Create("http://
api.recaptcha.net");
WebResponse httpResponse = null;
httpResponse = request.GetResponse();

}


Marc

On Jul 3, 5:14 pm, "Adrian Godong" <adrian.god...@gmail.com> wrote:
> Well, definitely not happening to me. :D
>
> Can you create a small app just to test connectivity with reCAPTCHA
> servers? Say, create an aspx page and then on page load execute a
> WebRequest.GetResponse() to reCAPTCHA server URI and see what you get.
>
> I still think this is a firewall problem. Have you checked your
> firewall? (port 80 outbound, not inbound)
>

Marc Miles

unread,
Jul 4, 2007, 12:01:40 AM7/4/07
to reCAPTCHA
BTW, I just put myself in the DMZ as well as have 80 TCP directed to
my IP.

Marc

On Jul 3, 8:56 pm, Marc Miles <marcmi...@gmail.com> wrote:
> Well, Im getting the problem, and I dont think its my firewall, its
> the api URI specifically, see below (latest code from your site and
> c#.net 2.0)
>

> For the URL below usinghttp://api.recaptcha.netreturns a 404 not
> found, but usinghttp://www.google.comandhttp://api-verify.recaptcha.net/verify

> > > > > Microsoft MVPhttps://mvp.support.microsoft.com/profile/Adrian-Hidequoted text -

reCAPTCHA Support

unread,
Jul 4, 2007, 12:23:42 AM7/4/07
to reca...@googlegroups.com
Ardian -- Did you set the protocol version to 1.0 as Joseph Hill did? Last time I looked at your code, I remember that you basically caught any exception returned while doing the reCAPTCHA request then turned that into not reachable. It might help to log that exception to figure this issue out.

Adrian Godong

unread,
Jul 4, 2007, 12:37:12 AM7/4/07
to reca...@googlegroups.com
No, not yet. I've used WebRequest object which doesn't have that
setting. I'll have to use HttpWebRequest to accomodate that.

I'll put the logging on next version.

To Steve/Marc: try breaking at the catch and post the ex.Message here.
Maybe it'll shed some light.

Marc Miles

unread,
Jul 4, 2007, 12:46:16 AM7/4/07
to reCAPTCHA
That was my ex.message, 404

[System.Net.WebException] = {"The remote server returned an error:
(404) Not Found."}


Server Error in '/MilkCartonProject' Application.
The remote server returned an error: (404) Not Found.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The remote server returned
an error: (404) Not Found.

Source Error:

Line 24: {
Line 25:
Line 26: throw;
Line 27: }
Line 28:


Source File: c:\Inetpub\wwwroot\MilkCartonProject\test3.aspx.cs
Line: 26

Stack Trace:

[WebException: The remote server returned an error: (404) Not Found.]
System.Net.HttpWebRequest.GetResponse() +1501755
test3.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot
\MilkCartonProject\test3.aspx.cs:26
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,
Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1061


On Jul 3, 9:37 pm, "Adrian Godong" <adrian.god...@gmail.com> wrote:
> No, not yet. I've used WebRequest object which doesn't have that
> setting. I'll have to use HttpWebRequest to accomodate that.
>
> I'll put the logging on next version.
>
> To Steve/Marc: try breaking at the catch and post the ex.Message here.
> Maybe it'll shed some light.
>

> On 7/4/07, reCAPTCHA Support <supp...@recaptcha.net> wrote:
>
>
>
> > Ardian -- Did you set the protocol version to 1.0 as Joseph Hill did? Last
> > time I looked at your code, I remember that you basically caught any
> > exception returned while doing the reCAPTCHA request then turned that into
> > not reachable. It might help to log that exception to figure this issue out.
>

> > On 7/3/07, Adrian Godong <adrian.god...@gmail.com> wrote:
>
> > > Well, definitely not happening to me. :D
>
> > > Can you create a small app just to test connectivity with reCAPTCHA
> > > servers? Say, create an aspx page and then on page load execute a
> > > WebRequest.GetResponse() to reCAPTCHA server URI and see what you get.
>
> > > I still think this is a firewall problem. Have you checked your
> > > firewall? (port 80 outbound, not inbound)
>

> > > Adrian Godong
> > > adrian.god...@gmail.com


> > > Microsoft MVP
> > >https://mvp.support.microsoft.com/profile/Adrian
>
> > >http://recaptcha.net
>
> --
> Adrian Godong

> adrian.god...@gmail.com
> Microsoft MVPhttps://mvp.support.microsoft.com/profile/Adrian

Marc Miles

unread,
Jul 4, 2007, 1:06:33 AM7/4/07
to reCAPTCHA
Also, I can open http://api.recaptcha.net just fine (ping/browse).

If you want to give me a buzz feel free to do so within the next two
hours as I'm working on it now 425-457-3757

On Jul 3, 9:37 pm, "Adrian Godong" <adrian.god...@gmail.com> wrote:
> No, not yet. I've used WebRequest object which doesn't have that
> setting. I'll have to use HttpWebRequest to accomodate that.
>
> I'll put the logging on next version.
>
> To Steve/Marc: try breaking at the catch and post the ex.Message here.
> Maybe it'll shed some light.
>

> On 7/4/07, reCAPTCHA Support <supp...@recaptcha.net> wrote:
>
>
>
> > Ardian -- Did you set the protocol version to 1.0 as Joseph Hill did? Last
> > time I looked at your code, I remember that you basically caught any
> > exception returned while doing the reCAPTCHA request then turned that into
> > not reachable. It might help to log that exception to figure this issue out.
>

> > On 7/3/07, Adrian Godong <adrian.god...@gmail.com> wrote:
>
> > > Well, definitely not happening to me. :D
>
> > > Can you create a small app just to test connectivity with reCAPTCHA
> > > servers? Say, create an aspx page and then on page load execute a
> > > WebRequest.GetResponse() to reCAPTCHA server URI and see what you get.
>
> > > I still think this is a firewall problem. Have you checked your
> > > firewall? (port 80 outbound, not inbound)
>

> > > Adrian Godong
> > > adrian.god...@gmail.com


> > > Microsoft MVP
> > >https://mvp.support.microsoft.com/profile/Adrian
>
> > >http://recaptcha.net
>
> --
> Adrian Godong

> adrian.god...@gmail.com
> Microsoft MVPhttps://mvp.support.microsoft.com/profile/Adrian

reCAPTCHA Support

unread,
Jul 4, 2007, 1:19:32 AM7/4/07
to reca...@googlegroups.com
From the logs, it looks like you've been getting 417 (Expectation Failed) errors. Joseph Hill solved this by setting the HTTP Protocol version to 1.0. From an email with him:

> > 2) When I call the verify service from the asp.net server, I get an exception that states: "The remote server returned an error: (417) Expectation Failed." I'm
> > able to work around it by adding this setting to my Web.config:
> > <servicePointManager expect100Continue="false" />
> > However, I'd like to avoid asking people to make that configuration change if possible. Do you have any idea as to how you can compensate for this at the verify
> > server? You can find a little more information about this here: http://msdn2.microsoft.com/en-us/library/system.net.servicepointmanager.expect100continue.aspx*
>
> Maybe try going back to http 1.0 (ProtocolVersion = blah). Otherwise, it looks like there's a static property, you can set it and try to restore it I guess.
>


Btw, if you have problems with the server, it'd really help to know your IP address :-). The fact that you visited http://api.recaptcha.net with your browser was the only thing that let me find you in the logs.

> > > > > > > >    System.Web.UI.Page.Validate () +133

Marc Miles

unread,
Jul 4, 2007, 2:13:43 AM7/4/07
to reCAPTCHA
IP is 71.113.114.152 (my router anyway)

Still having issues implementing your suggestion, doesnt seem to be
easy (as in I cant get any of these attempts to work)
http://haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx
http://www.infinitec.de/articles/development/it000001.aspx

On Jul 3, 10:19 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> From the logs, it looks like you've been getting 417 (Expectation Failed)
> errors. Joseph Hill solved this by setting the HTTP Protocol version to 1.0.
> From an email with him:
>
> > > 2) When I call the verify service from the asp.net server, I get an
>
> exception that states: "The remote server returned an error: (417)
> Expectation Failed." I'm> > able to work around it by adding this setting to my Web.config:
> > > <servicePointManager expect100Continue="false" />
> > > However, I'd like to avoid asking people to make that configuration
>
> change if possible. Do you have any idea as to how you can compensate for
> this at the verify> > server? You can find a little more information about this here:
>

> http://msdn2.microsoft.com/en-us/library/system.net.servicepointmanag...


>
> > Maybe try going back to http 1.0 (ProtocolVersion = blah). Otherwise, it
>
> looks like there's a static property, you can set it and try to restore it I
> guess.
>
>
>
> Btw, if you have problems with the server, it'd really help to know your IP

> address :-). The fact that you visitedhttp://api.recaptcha.netwith your


> browser was the only thing that let me find you in the logs.
>

> ...
>
> read more »

reCAPTCHA Support

unread,
Jul 4, 2007, 2:20:07 AM7/4/07
to reca...@googlegroups.com
It looks like these requests are .net's attempt to post:

71.113.114.152 api.recaptcha.net - [03/Jul/2007:23:58:33 -0400] "GET / HTTP/1.1" 404 114 "-" "-"
71.113.114.152 api.recaptcha.net - [04/Jul/2007:00:45:05 -0400] "GET / HTTP/1.1" 404 114 "-" "-"
71.113.114.152 api.recaptcha.net - [04/Jul/2007:02:05:43 -0400] "GET / HTTP/1.1" 404 114 "-" "-"
71.113.114.152 api.recaptcha.net - [04/Jul/2007:02:11:36 -0400] "GET / HTTP/1.1" 404 114 "-" "-"

Make sure to do a POST to /verify on api-verify.recaptcha.net

Also, take a look at Joseph Hill's code which avoids the Expect Continue issue:

http://recaptcha.googlecode.com/svn/trunk/recaptcha-plugins/dotnet/src/Recaptcha/RecaptchaValidator.cs

Specifically:

request.ProtocolVersion = new Version("1.0");


On 7/3/07, Marc Miles <marc...@gmail.com> wrote:
> >    System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp,

> > Object o, Object t, EventArgs e) +15
> >    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
> > sender, EventArgs e) +34
> >    System.Web.UI.Control.OnLoad (EventArgs e) +99

Marc Miles

unread,
Jul 4, 2007, 2:37:52 AM7/4/07
to reCAPTCHA
I think its working now.......... :) Just need to look at the
RecapthcaControl to see whats being returned, the gui just loads with
another challenge, but, it does successfully notify if I typed
incorrectly (which is new). :)

So, I updated the control, see code below. I added a property that
sets System.Net.ServicePointManager.Expect100Continue to false on
DoValidate() start, and turns it back on at the end of that function.
Lol, never had to type a var with the word "dot" in it before.


// MIT License:

//Copyright (c) 2007 Adrian Godong

//Permission is hereby granted, free of charge, to any person
obtaining a copy
//of this software and associated documentation files (the
"Software"), to deal
//in the Software without restriction, including without limitation
the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell
//copies of the Software, and to permit persons to whom the Software
is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be
included in
//all copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN
//THE SOFTWARE.

using System;
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebVenture.Library.CommonUI
{
[ToolboxData("<{0}:RecaptchaControl Theme=red runat=server />")]
public class RecaptchaControl : WebControl, IValidator
{
private const string RECAPTCHA_CHALLENGE_FIELD =
"recaptcha_challenge_field";
private const string RECAPTCHA_RESPONSE_FIELD =
"recaptcha_response_field";

private String standardApiBaseUrl = "http://api.recaptcha.net"; //
TODO: create public property
private String secureApiBaseUrl = "https://api-
secure.recaptcha.net"; //TODO: create public property
private String verifyApiUrl = "http://api-verify.recaptcha.net/
verify"; //TODO: create public property
private String publicKey;
private String privateKey;
private Boolean isSecure;
private String error = "";
private RecaptchaTheme theme;
private Boolean useHTTPProt1dotZero;

public RecaptchaControl()
{
this.publicKey =
ConfigurationManager.AppSettings["RecaptchaPublicKey"];
this.privateKey =
ConfigurationManager.AppSettings["RecaptchaPrivateKey"];
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Page.Validators.Add(this);
}

//TODO: implement custom OnUnload method if necessary
//protected override void OnUnload(EventArgs e)
//{
// base.OnUnload(e);
//}

#region Public Properties
[Category("Settings")]
public String PublicKey
{
get { return this.publicKey; }
set { this.publicKey = value; }
}

[Category("Settings")]
public String PrivateKey
{
get { return this.privateKey; }
set { this.privateKey = value; }
}

[Category("Settings")]
[DefaultValue(false)]
public Boolean IsSecure
{
get { return this.isSecure; }
set { this.isSecure = value; }
}

[Category("Settings")]
[DefaultValue(RecaptchaTheme.red)]
public RecaptchaTheme Theme
{
get { return this.theme; }
set { this.theme = value; }
}

[Category("Settings")]
[DefaultValue(0)]
public override Int16 TabIndex
{
get { return base.TabIndex; }
set { base.TabIndex = value; }
}


[Category("Settings")]
[DefaultValue(false)]
public Boolean UseHTTPProt1dotZero
{
get { return this.useHTTPProt1dotZero; }
set { this.useHTTPProt1dotZero = value; }
}

#endregion

#region Overriden Methods
protected override void Render(HtmlTextWriter writer)
{
RenderContents(writer);
}

protected override void RenderContents(HtmlTextWriter output)
{
// <script> setting
output.RenderBeginTag(HtmlTextWriterTag.Script);
output.Indent++;
output.WriteLine("var RecaptchaOptions = {");
output.Indent++;
output.WriteLine("theme : '{0}',", this.theme.ToString());
output.WriteLine("tabindex : {0}", base.TabIndex);
output.Indent--;
output.WriteLine("};");
output.Indent--;
output.RenderEndTag();

// <script> display
output.AddAttribute(HtmlTextWriterAttribute.Type, "text/
javascript");
output.AddAttribute(HtmlTextWriterAttribute.Src,
GenerateChallengeUrl(false), false);
output.RenderBeginTag(HtmlTextWriterTag.Script);
output.RenderEndTag();

// <noscript> display
output.RenderBeginTag(HtmlTextWriterTag.Noscript);
output.Indent++;
output.AddAttribute(HtmlTextWriterAttribute.Src,
GenerateChallengeUrl(true), false);
output.AddAttribute(HtmlTextWriterAttribute.Width, "500");
output.AddAttribute(HtmlTextWriterAttribute.Height, "300");
output.AddAttribute("frameborder", "0");
output.RenderBeginTag(HtmlTextWriterTag.Iframe);
output.RenderEndTag();
output.RenderBeginTag(HtmlTextWriterTag.Br);
output.RenderEndTag();
output.AddAttribute(HtmlTextWriterAttribute.Name,
"recaptcha_challenge_field");
output.AddAttribute(HtmlTextWriterAttribute.Rows, "3");
output.AddAttribute(HtmlTextWriterAttribute.Cols, "40");
output.RenderBeginTag(HtmlTextWriterTag.Textarea);
output.RenderEndTag();
output.AddAttribute(HtmlTextWriterAttribute.Name,
"recaptcha_response_field");
output.AddAttribute(HtmlTextWriterAttribute.Value,
"manual_challenge");
output.AddAttribute(HtmlTextWriterAttribute.Type, "hidden");
output.RenderBeginTag(HtmlTextWriterTag.Input);
output.RenderEndTag();
output.Indent--;
output.RenderEndTag();
}
#endregion

#region IValidator Members
public string ErrorMessage
{
get { return this.error; }
set
{
throw new Exception("The method or operation is not
implemented.");
}
}

public bool IsValid
{
get { return (error == String.Empty); }
set
{
throw new Exception("The method or operation is not
implemented.");
}
}

public void Validate()
{
DoValidation();
}
#endregion

#region Private Methods
private void DoValidation()
{
if (this.useHTTPProt1dotZero)
System.Net.ServicePointManager.Expect100Continue = false;

WebRequest request = WebRequest.Create(GenerateVerifyUrl());
request.Method = "POST";

request.ContentType = "application/x-www-form-urlencoded";


String postData =
String.Format("privatekey={0}&remoteip={1}&challenge={2}&response={3}",
this.PrivateKey,
this.Page.Request.UserHostAddress,
this.Context.Request.Form[RECAPTCHA_CHALLENGE_FIELD],
this.Context.Request.Form[RECAPTCHA_RESPONSE_FIELD]);
byte[] postBytes = Encoding.UTF8.GetBytes(postData);

using (Stream requestStream = request.GetRequestStream())
requestStream.Write(postBytes, 0, postBytes.Length);

WebResponse httpResponse = null;
string[] results = null;
try
{
httpResponse = request.GetResponse();
using (Stream receiveStream =
httpResponse.GetResponseStream())
{
using (StreamReader readStream = new
StreamReader(receiveStream, Encoding.UTF8))
{
results = readStream.ReadToEnd().Split();
}
}
}
catch (WebException ex) //timeout
{
results = new string[] { "false", "recaptcha-not-reachable" };
}
finally
{
if (httpResponse != null) httpResponse.Close();
}

switch (results[0])
{
case "true":
this.error = String.Empty;
break;
case "false":
this.error = results[1];
break;
default:
throw new InvalidProgramException("Unknown status
response.");
}
if (this.useHTTPProt1dotZero)
System.Net.ServicePointManager.Expect100Continue = true;
}

private string GenerateChallengeUrl(Boolean noScript)
{
StringBuilder urlBuilder = new StringBuilder();
urlBuilder.Append(this.isSecure ? this.secureApiBaseUrl :
this.standardApiBaseUrl);
//TODO: add validation if last character is "/", move to
property when set
urlBuilder.Append(noScript ? "/noscript?" : "/challenge?");
urlBuilder.AppendFormat("k={0}&error={1}", this.publicKey,
this.error);
return urlBuilder.ToString();
}

private string GenerateVerifyUrl()
{
StringBuilder urlBuilder = new StringBuilder();
urlBuilder.Append(this.verifyApiUrl);
return urlBuilder.ToString();
}
#endregion
}

public enum RecaptchaTheme : byte
{
red,
white,
blackglass
}
}


On Jul 3, 11:13 pm, Marc Miles <marcmi...@gmail.com> wrote:
> IP is 71.113.114.152 (my router anyway)
>
> Still having issues implementing your suggestion, doesnt seem to be

> easy (as in I cant get any of these attempts to work)http://haacked.com/archive/2004/05/15/http-web-request-expect-100-con...http://www.infinitec.de/articles/development/it000001.aspx


>
> On Jul 3, 10:19 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
>
> > From the logs, it looks like you've been getting 417 (Expectation Failed)
> > errors. Joseph Hill solved this by setting the HTTP Protocol version to 1.0.
> > From an email with him:
>

> > > > 2) When I call the verify service from theasp.netserver, I get an

> ...
>
> read more »

reCAPTCHA Support

unread,
Jul 4, 2007, 2:45:05 AM7/4/07
to reca...@googlegroups.com
Awesome! Glad to hear you got it working.

A few points about integrating this back into SVN:

  1. I liked Joseph's way of using the HTTP 1.0 protocol directly rather than the static property -- setting a static flag is a bit of bad style ;-).
  2. I don't think we need to make this an option, it should be on by default and not able to be turned off.

Also, one other thing from seeing the code again, I think we should fix up this:



     String postData =
String.Format("privatekey={0}&remoteip={1}
&challenge={2}&response={3}",

I'm somewhat worried that somebody who sees a CAPTCHA with an "&" in it would get their request corrupted.

-b


On 7/3/07, Marc Miles <marc...@gmail.com> wrote:
      output.AddAttribute (HtmlTextWriterAttribute.Height, "300");

Marc Miles

unread,
Jul 4, 2007, 2:53:32 AM7/4/07
to reCAPTCHA
In .net 2.0 the object is WebRequest not HttpWebRequest, and I dont
think WebRequest has the ability to set the protocol version
directly....

On Jul 3, 11:20 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> It looks like these requests are .net's attempt to post:
>
> 71.113.114.152 api.recaptcha.net - [03/Jul/2007:23:58:33 -0400] "GET /
> HTTP/1.1" 404 114 "-" "-"
> 71.113.114.152 api.recaptcha.net - [04/Jul/2007:00:45:05 -0400] "GET /
> HTTP/1.1" 404 114 "-" "-"
> 71.113.114.152 api.recaptcha.net - [04/Jul/2007:02:05:43 -0400] "GET /
> HTTP/1.1" 404 114 "-" "-"
> 71.113.114.152 api.recaptcha.net - [04/Jul/2007:02:11:36 -0400] "GET /
> HTTP/1.1" 404 114 "-" "-"
>
> Make sure to do a POST to /verify on api-verify.recaptcha.net
>
> Also, take a look at Joseph Hill's code which avoids the Expect Continue
> issue:
>

> http://recaptcha.googlecode.com/svn/trunk/recaptcha-plugins/dotnet/sr...


>
> Specifically:
>
> request.ProtocolVersion = new Version("1.0");
>

> On 7/3/07, Marc Miles <marcmi...@gmail.com> wrote:
>
>
>
> > IP is 71.113.114.152 (my router anyway)
>
> > Still having issues implementing your suggestion, doesnt seem to be
> > easy (as in I cant get any of these attempts to work)
>

> >http://haacked.com/archive/2004/05/15/http-web-request-expect-100-con...

> > > > System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,


> > > > Object o, Object t, EventArgs e) +15
> > > > System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
> > > > sender, EventArgs e) +34

> > > > System.Web.UI.Control.OnLoad(EventArgs e) +99

> ...
>
> read more »

reCAPTCHA Support

unread,
Jul 4, 2007, 2:59:04 AM7/4/07
to reca...@googlegroups.com
The factory method always returns a HttpWebRequest, so you can just cast it.

On 7/3/07, Marc Miles <marc...@gmail.com > wrote:
> > > >    System.Net.HttpWebRequest.GetResponse () +1501755

> > > >    test3.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot
> > > > \MilkCartonProject\test3.aspx.cs:26
> > > >    System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp,

Adrian Godong

unread,
Jul 4, 2007, 3:03:18 AM7/4/07
to reca...@googlegroups.com
Great. I'll merge it ASAP.

Marc Miles

unread,
Jul 4, 2007, 3:17:22 AM7/4/07
to reCAPTCHA
Just wanted to say thanks for the awesome support and the code. Being
able to implement a free captcha like this is huge, especially for the
non profit I'm working on.

Marc

> > On Jul 3, 10:19 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
>
> > > From the logs, it looks like you've been getting 417 (Expectation Failed)
> > > errors. Joseph Hill solved this by setting the HTTP Protocol version to 1.0.
> > > From an email with him:
>
> > > > > 2) When I call the verify
>

> ...
>
> read more »

Marc Miles

unread,
Jul 4, 2007, 2:49:45 PM7/4/07
to reCAPTCHA
Actually, using my implementation wouldn't be a good thing, as
subsequent requests have a chance at failing.

Basically, the first request would enter DoValidation() and set
ServicePointManager.Expect100Continue = true and then another request
would come in and start its DoValidation, but, the first request could
set ServicePointManager.Expect100Continue = false prior to the second
one actually finishing.

So I kept the property and instead am doing the following....

HttpWebRequest request =
(HttpWebRequest)HttpWebRequest.Create(GenerateVerifyUrl());
if (this.useHTTPProt1dotZero)


request.ProtocolVersion = new Version("1.0");


On Jul 4, 12:03 am, "Adrian Godong" <adrian.god...@gmail.com> wrote:
> Great. I'll merge it ASAP.
>

> ...
>
> read more »

Marc Miles

unread,
Jul 4, 2007, 2:55:36 PM7/4/07
to reCAPTCHA
Hmmm, that code snippet doesn't work. I keep getting "Incorrect Try
Again".

> ...
>
> read more »

mtbvfr

unread,
Jul 10, 2007, 6:56:42 PM7/10/07
to reCAPTCHA
Hi All,

I have discovered the same problem for the 1.1 version.

I am testing on my own home PC which uses Windows 2000 Server for the
OS.

I have replaced my keys with "xxxxxxxx".

For the following line in my aspx file:
<recatpcha:recaptchavalidator ID="RecaptchaValidator1" runat="server"
PublicKey="xxxxxxxx" PrivateKey="xxxxxxxx" Theme="BlackGlass"
ControlToValidate="TextBox1"></recatpcha:recaptchavalidator>

When using it in Mozilla and viewing the Source Code for the generated
page, the following is generated:

&nbsp;

When using it in IE6 and viewing the Source Code for the generated
page, the following is generated:

<script>var RecaptchaOptions = { theme : 'blackglass', tabindex: 0 };</
script>
<script type="text/javascript"
src="http://api.recaptcha.net/challenge?k=xxxxxxxx">
</script>

<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=xxxxxxxx"
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40">
</textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
<span id="RecaptchaValidator1" controltovalidate="TextBox1"
style="color:Red;visibility:hidden;"></span>


So, what is going on guys? I have 20 years programming experience but
still only limited experience with .Net Internet and I also looked at
the source for RecaptchaValidator.cs and couldn't determine what would
be causing the RenderBeginTag function to not be executed.

I am using this in a VB.Net 1.1 project.

Thanks and please hurry back,
Michael Holberton
Hospedaje Los Jardines & Sacred Valley Mountain Bike Tours
Cusco Database Development and Cycling Services
http://www.machawasi.com/
http://machawasi.blogspot.com/
http://databaseservices.blogspot.com
http://serviciosdeciclismodelperu.googlepages.com

On Jun 28, 8:04 am, Steve Marchessault <caretechsoluti...@gmail.com>
wrote:
> I noticed when using the above implementation of reCAPTCHA in C# that
> the control displays correctly on load in IE but in all other browsers
> (FireFox, Safari, etc) it does not display on load and displays with
> an error on postback. I was looking at how the control renders itself
> and noticed the following code:
>
> <span id="RecaptchaValidator1" controltovalidate="RecaptchaValidator1"
> style="color:Red;visibility:hidden;"></span>
>
> The style tag has the visibility property set to hidden which IE must
> be ignoring but other browsers are using. I can't find in the source
> code where this is getting set. Does anyone else experience the same
> problem?

Reply all
Reply to author
Forward
0 new messages