Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 615663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:14:40+00:00 2026-05-13T18:14:40+00:00

I’m part of the way through implementing a native CAPTCHA (i.e. not reCaptcha) solution

  • 0

I’m part of the way through implementing a native CAPTCHA (i.e. not reCaptcha) solution in my app. I’ve built it along the lines of Sanderson’s book, Pro ASP.NET MVC Framework. It’s built into a HtmlHelper class so I can call it in my view like

<%= Html.Captcha("nameOfGeneratedCaptchaIdField")%>

However, to use this I’ll need a way to allow for it’s re-generation. i.e. If you can’t read this, click [here].

This [here] I want to be a controller action that generates the captcha image and spits back the html. (I’ll use this in an Ajax.ActionLink link.)

But I’m having trouble figuring out how to do this in my controller. How do I get a handle on the HtmlHelper that’s required by a HtmlHelper

public ActionResult RegenerateCaptcha(string name)
{
    var myHtmlHelper = ???;
    var newCaptcha = Captcha.Helpers.CaptchaHelper.Captcha(myHtmlHelper, name);


    if (Request.IsAjaxRequest())
    {
        return Content(newCaptcha.ToString());
    }
    else
    {
        return Content(newCaptcha.ToString());
    }
}

My Captcha Helper is coded as:

// this is invoked in a view by <%= Html.Captcha("myCaptcha") %>
public static string Captcha(this HtmlHelper html, string name)
{
    // Pick a GUID to represent this challenge
    string challengeGuid = Guid.NewGuid().ToString();
    // Generate and store a random solution text
    var session = html.ViewContext.HttpContext.Session;
    session[SessionKeyPrefix + challengeGuid] = MakeRandomSolution();

    // Render an <IMG> tag for the distorted text,
    var urlHelper = new UrlHelper(html.ViewContext.RequestContext);
    string url = urlHelper.Action("Render", "CaptchaImage", new{challengeGuid});
    // fill it with a newly rendered image url, 
    // plus a hidden field to contain the challenge GUID
    return string.Format(ImgFormat, name, challengeGuid, url);
}

I guess I can just copy that out of the Helper and paste it into my controller action, but that seems a bit ghetto…

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:14:40+00:00Added an answer on May 13, 2026 at 6:14 pm

    You don’t have to create html helpers in your controller. You should create partial view returning captcha and return PartialViewResult:

    public PartialViewResult Captcha()
    {
        return PartialView("Captcha");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to loop through a bunch of documents I have to put
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.