views:

69

answers:

2

I'm writing an ASP.NET MVC site where I want to display a CAPTCHA when content that a user submits fails my Akismet spam check. I know how to display the CAPTCHA, but I'm having trouble imagining and planning the architecture for this. Here's what I'm currently thinking:

  1. User submits content via HTTP POST
  2. The action that handles the submission runs an Akismet check
  3. If the Akismet check fails, the action calls return RedirectToAction() and sends the user off to the CAPTCHA action
  4. The CAPTCHA action displays a CAPTCHA by using the MvcReCaptcha library, then processes the CAPTCHA result
  5. If the user succeeds at validation, the CAPTCHA action returns the user to the original action.

My question is: how should I engineer the return of the user to the original action? I need to somehow carry the data that the user submitted, as well as the name of the original action, into the CAPTCHA action so that RedirectToAction includes both.

Any ideas? Thanks in advance.


UPDATE:

Mare's answer below linked to a recording of a session at PDC 2008 where Jeff Atwood showed a little bit of the CAPTCHA code that Stack Overflow uses. The end result that I'm going for is essentially how CAPTCHAs work here on Stack Overflow.

The CAPTCHA submission code that Jeff showed does the following:

  1. Check `Session["captcha-returnUrl"] for content; if no content, returnUrl = "/".
  2. Validate the CAPTCHA submission.
  3. If the CAPTCHA was submitted correctly, return Redirect(resultUrl);

That solves part of my question. However, there are still a few things that I don't understand:

  • How do I set Session["captcha-returnUrl"] from the method that calls the CAPTCHA?
  • What do I set the return URL to? I want successful CAPTCHA submission to trigger the form submission that the user was doing originally - how do I convey the form path and the form data?
+1  A: 

Maybe you can find some ideas in an old video from PDC 08 where Jeff Atwood talks about Recaptcha implementation at Stack Overflow, its somewhere in the middle of the video: http://channel9.msdn.com/pdc2008/PC21/

Hope it helps

mare
A: 

This link might help.

PSTCC
I already have all that - isn't that just the MvcReCaptcha library? Thanks anyhow! :)
Maxim Zaslavsky