I have an MVC application that I’m trying to add the ManagedFusion.Web.Captcha.CaptchaImageHandler into so that I can write the following code :
<label for="captcha">Enter @Html.Raw(Business.Captcha.CaptchaImage(Html, 50, 180)) Below</label>
and have the image appear. The code for that class is just cut and paste from the examples online:
public static string CaptchaImage(this HtmlHelper helper, int height, int width) {
ManagedFusion.Web.Controls.CaptchaImage image = new ManagedFusion.Web.Controls.CaptchaImage {
Height = height,
Width = width,
};
HttpRuntime.Cache.Add(image.UniqueId, image,
null,
DateTime.Now.AddSeconds(ManagedFusion.Web.Controls.CaptchaImage.CacheTimeOut),
Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable,
null);
StringBuilder stringBuilder = new StringBuilder(256);
stringBuilder.Append("<input type=\"hidden\" name=\"captcha-guid\" value=\"");
stringBuilder.Append(image.UniqueId);
stringBuilder.Append("\" />");
stringBuilder.AppendLine();
stringBuilder.Append("<img src=\"");
stringBuilder.Append("/captcha.ashx?guid=" + image.UniqueId);
stringBuilder.Append("\" alt=\"CAPTCHA\" width=\"");
stringBuilder.Append(width);
stringBuilder.Append("\" height=\"");
stringBuilder.Append(height);
stringBuilder.Append("\" />");
return stringBuilder.ToString();
}
I’ve added the following to my web.config
<system.web>
<httpHandlers>
<add verb="GET" path="test.sample" type="ManagedFusion.Web.Handlers.CaptchaImageHandler, ManagedFusion.Web.Captcha" validate="false" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" >
</modules>
<handlers>
<add name="CaptchaImageHandler" verb="GET" path="captcha.ashx" type="ManagedFusion.Web.Handlers.CaptchaImageHandler, ManagedFusion.Web.Captcha" />
</handlers>
All previous SO questions point to the system.web->httpHandlers getting picked up by Cassini and the system.webServer->handlers getting picked up by IIS 7. But whenever I navigate to the view that has the aforementioned code, I always get a 404 for the /captcha.ashx. There is no route ignore rule in the global.asax. What is going on here? It’s like nothing I do will get the handler to fire either on my local machine or on a deployed IIS 7 instance.
In the Global.asax file, I needed to add the ignore route before the default route mapping, so the whole method looks like this: