How can I use CaptchaMvc in Areas View?

Mar 12, 2013 at 12:14 PM
I tried to use CaptchaMvc in Areas View, but the captcha picture can't be load. I want to know what can I do to resolve this problem.
Coordinator
Mar 14, 2013 at 5:28 PM
Hi there,
To fix this issue you can change the Url, which are generated by the captcha to an Url which is suitable for your route.
Since version 2.2, you can write this code:
//default implementation
private string RefreshUrlFactory(UrlHelper urlHelper, KeyValuePair<string, ICaptchaValue> keyValuePair)
{
    return urlHelper.Action("Refresh", "DefaultCaptcha");
}

//default implementation
private string ImageUrlFactory(DefaultCaptchaManager captchaManager, UrlHelper urlHelper, KeyValuePair<string, ICaptchaValue> keyValuePair)
{
    return urlHelper.Action("Generate", "DefaultCaptcha",
                            new RouteValueDictionary {{captchaManager.TokenParameterName, keyValuePair.Key}});
}

/// <summary>
/// Starts the application.
/// </summary>
public void Application_Start()
{
    var captchaManager = (DefaultCaptchaManager)CaptchaUtils.CaptchaManager;
    captchaManager.ImageUrlFactory = (helper, pair) => ImageUrlFactory(captchaManager, helper, pair);
    captchaManager.RefreshUrlFactory = RefreshUrlFactory;

    //......
}
Regards,
Vyacheslav Volkov
May 5, 2013 at 12:43 PM
Thanks Vyacheslav Volkov.
Actually your above example does not work.Please check it for views in area section.It show the following compile error

It does not show any error.but do not show the captcha image.