Routes causing image to fail....

Feb 20, 2013 at 8:33 AM
Edited Feb 20, 2013 at 8:35 AM
My MVC Razor site is set up the following way.
http://www.mydomain.com/user/section>

Where user is the user id of the customer and section is one of five menu options.
So as follows....

http://www.mydomain.com/3434/Home
<br>
http://www.mydomain.com/3434/Profile>
http://www.mydomain.com/3434/Stats

<br>
To achieve this I have a route set up as follows....
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = " " }
        );
I believe this is causing a problem for the MVC plugin because I think my route is overriding the captcha image path that is generated since it has the same URL structure as the above links.

Basically I'm getting a 404 in the page for the following:
http://www.mydomain.com/3434/DefaultCaptcha/Generate?t=8f9ebad2e09e49ea899c384e70d69e28
<br>
Does this make any sense?
Coordinator
Mar 7, 2013 at 12:41 PM
Hi there,

Sorry for the late reply. Yes it may break the url that Captcha generates.
In order to control this, you can override methods to generate url, this is default implementation:
public class CapchaManager : DefaultCaptchaManager
{

    #region Overrides of DefaultCaptchaManager

    protected override string GenerateImageUrl(UrlHelper urlHelper, KeyValuePair<string, ICaptchaValue> captchaPair)
    {
        return urlHelper.Action("Generate", "DefaultCaptcha",
                                        new RouteValueDictionary { { TokenParameterName, captchaPair.Key } });
    }

    protected override string GenerateRefreshUrl(UrlHelper urlHelper, KeyValuePair<string, ICaptchaValue> captchaPair)
    {
        return urlHelper.Action("Refresh", "DefaultCaptcha");
    }

    #endregion
}
and then put this code when the application starts:
CaptchaUtils.CaptchaManager = new CapchaManager();
Regards,
Vyacheslav Volkov
May 5, 2013 at 12:42 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

'CaptchaMvc.Infrastructure.DefaultCaptchaManager' does not contain a constructor that takes 0 arguments.can you please review it and update with proper solution for views in area section.