Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc HttpHandler从未被调用_Asp.net Mvc_Captcha_Httphandler - Fatal编程技术网

Asp.net mvc HttpHandler从未被调用

Asp.net mvc HttpHandler从未被调用,asp.net-mvc,captcha,httphandler,Asp.net Mvc,Captcha,Httphandler,我有一个MVC应用程序,我正在尝试将ManagedFusion.Web.Captcha.CaptchaImageHandler添加到其中,以便编写以下代码: <label for="captcha">Enter @Html.Raw(Business.Captcha.CaptchaImage(Html, 50, 180)) Below</label> 在下面输入@Html.Raw(Business.Captcha.CaptchaImage(Html,50180)) 并

我有一个MVC应用程序,我正在尝试将ManagedFusion.Web.Captcha.CaptchaImageHandler添加到其中,以便编写以下代码:

<label for="captcha">Enter @Html.Raw(Business.Captcha.CaptchaImage(Html, 50, 180))  Below</label>
在下面输入@Html.Raw(Business.Captcha.CaptchaImage(Html,50180))
并显示图像。该类的代码仅从在线示例中剪切和粘贴:

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();
        }
public静态字符串CaptchaImage(此HtmlHelper助手,int-height,int-width){
ManagedFusion.Web.Controls.CaptchaImage=新建ManagedFusion.Web.Controls.CaptchaImage{
高度=高度,
宽度=宽度,
};
HttpRuntime.Cache.Add(image.UniqueId,image,
无效的
DateTime.Now.AddSeconds(ManagedFusion.Web.Controls.CaptchaImage.CacheTimeOut),
Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable,
无效);
StringBuilder StringBuilder=新的StringBuilder(256);
stringBuilder.Append(“”);
stringBuilder.AppendLine();
stringBuilder.Append(“”);
返回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被Cassini接收,system.webServer->handlers被IIS 7接收。但每当我导航到包含上述代码的视图时,我总是会得到一个404作为/captcha.ashx。global.asax中没有路由忽略规则。这是怎么回事?我所做的一切都不会让处理程序在本地计算机或已部署的IIS 7实例上启动。

在Global.asax文件中,我需要在默认路由映射之前添加忽略路由,因此整个方法如下所示:

public static void RegisterRoutes(RouteCollection routes) {
        routes.Ignore("captcha.ashx");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
    }