2
我有我想要的ManagedFusion.Web.Captcha.CaptchaImageHandler加入到這樣我就可以寫代碼如下MVC應用程序:的HttpHandler從來沒有得到所謂的
<label for="captcha">Enter @Html.Raw(Business.Captcha.CaptchaImage(Html, 50, 180)) Below</label>
,並有圖像顯示。這個類的代碼只是削減,並從在線的例子粘貼:
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();
}
我已經添加了以下到我的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>
以前所有的SO問題指向system.web-> httpHandlers越來越被卡西尼和system.webServer->處理程序拿到了IIS 7中。但是當我導航到具有上述代碼的視圖時,我總是得到/ captcha的404。 ASHX。 global.asax中沒有路由忽略規則。這裏發生了什麼?這就像我沒有做的任何事情都會讓處理程序在本地機器或部署的IIS 7實例上觸發。