HTTP处理程序不被调用 [英] HTTP Handler not being invoked

查看:225
本文介绍了HTTP处理程序不被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正确实现IHttpHandler的自定义HTTP处理程序。下面是我在我的webConfig已配置。如果我理解正确此块的的捕捉.TEST为扩展名的任何请求。

I have a custom HTTP Handler that properly implements IHttpHandler. Below is what I've configured in my webConfig. If I understand correctly this block should capture any requests with .test as the extension.

<handlers> 
    <add name="SampleHandler" verb="*" path="*.test" 
     type="TestApp.App_Start.CustomHandler, TestApp" />
</handlers>

然而,这个处理程序调用有史以来唯一一次是当我有应用到请求的URL三个路径深度。所有其他请求将404。

However, the only time this handler is ever invoked is when I have a path depth of three applied to the request URL. All other requests will 404.

有关实例的处理程序正常工作时的路径是:

For instance the handler works correctly when the path is:

localhost:XXX\some\fake\path\file.test

但不适合:

localhost:XXX\some\file.test

我使用ASP.NET MVC 5,并怀疑它是与路由。我也正在使用VS2013提供的样本项目,所以除了一个处理程序被添加到项目我真的没有做任何事情。

I am using ASP.NET MVC 5, and suspect it has something to do with the routing. I also am using the sample project provided in VS2013 so besides a handler being added to the project I really haven't done anything else.

更新:

我已经确定的缺省路由的干扰。

I've determined the default route is interfering.

  routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

有没有得到它甚至与配置工作这条路线的方式?

Is there way to get it working even with this route configured?

推荐答案

它看起来像路由与处理程序干扰。为了让处理器以收到我需要调用对当前RouteCollection忽略与.TEST任何路由在其中IgnoreRoute方法的要求:

It looks like the routing was interfering with the handler. In order to allow the handler to recieve the request I needed to call IgnoreRoute method against the current RouteCollection ignoring any routes with .test in them:

在RouteConfig类

Inside the RouteConfig class

  public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{resource}.test/");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }

现在的工作。有没有更好的方式来做到这一点?

It works now. Is there a better way to do this?

这篇关于HTTP处理程序不被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆