0

I'm follow this tutorial to use CAPTCHA in MVC application: http://coderjournal.com/2008/03/actionfilterattribute-aspnet-mvc-captcha/

I think this was made to ealry versions of ASP.NET MVC,because it doenst work for me.

Problem is that captcha image never shows,cause the custom handler (captcha.ashx) never gets the request.

In web.config:

<httpHandlers>
            <remove verb="*" path="*.asmx"/>
            <add verb="GET" validate="false" path="captcha.ashx" type="SCE.Models.Helpers.Captcha.CaptchaHandler"/>
        </httpHandlers>

The handler:

namespace SCE.Models.Helpers.Captcha
{
    public class CaptchaHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }
        public void ProcessRequest(HttpContext context)
        {
            string guid = context.Request.QueryString["guid"];
            CaptchaImage ci = CaptchaImage.GetCachedCaptcha(guid);

            if (String.IsNullOrEmpty(guid) || ci == null)
            {
                context.Response.StatusCode = 404;
                context.Response.StatusDescription = "Not found";
                context.ApplicationInstance.CompleteRequest();
                return;
            }

            using (Bitmap b = ci.RenderImage())
            {
                b.Save(context.Response.OutputStream, ImageFormat.Gif);
            }
            context.Response.ContentType = "image/png";
            context.Response.StatusCode = 200;
            context.Response.StatusDescription = "OK";
            context.ApplicationInstance.CompleteRequest();
        }
    }
}

It seem newer version of MVC has changed the way they route handler,but i dont know what exactly...

Any ideias to call the handler?

UPDATE: Here is the solution ive found: In global.asax file:

routes.IgnoreRoute("{filename}.ashx/{*pathInfo}");
ozsenegal
  • 4,055
  • 12
  • 49
  • 64
  • The code you link to is written for ASP.NET MVC Preview 1 or 2. You don't even need a custom HTTP handler for this. Are you just looking to use a CAPTCHA in your ASP.NET MVC site? – bzlm Aug 26 '10 at 21:50
  • possible duplicate of [How to Use Captcha in asp.net mvc](http://stackoverflow.com/questions/2286688/how-to-use-captcha-in-asp-net-mvc) – bzlm Aug 26 '10 at 21:51
  • yes captcha in mvc...but not recaptcha – ozsenegal Aug 26 '10 at 21:54

1 Answers1

1

Using MVC 2, and ReCaptcha this was a pretty elegant solution. IMHO

http://devlicio.us/blogs/derik_whittaker/archive/2008/12/02/using-recaptcha-with-asp-net-mvc.aspx

Dustin Laine
  • 37,935
  • 10
  • 86
  • 125
  • sorry i cant use recaptcha,cause ive already try,and it doenst work for me – ozsenegal Aug 26 '10 at 21:55
  • You could possible port this same method of implementation to whatever captcha you are using. I personally really like to be able to simple decorate my action with the captcha attribute. – Dustin Laine Aug 26 '10 at 22:06