为什么不会这个路由匹配 [英] Why won't this route match

查看:157
本文介绍了为什么不会这个路由匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些麻烦路线相匹配。

我使用的基带32 codeD INT作为短链接到幻灯片的Web应用程序。有5种不同的版本都幻灯片,和我使用的是首字母各个版本之间的区别。

的路由总是匹配,除了当基部32连接$ C $光盘INT的第一个字符是相同的字符指定幻灯片的版本。这种异常现象存在于所有5 preFIX字母:N,F,C,X,和h

怎么样的前两个字符是相同的,使这些线路不匹配?我茫然地明白这是怎么回事就在这里(路由信息时,不匹配,他们只是下跌至默认)。

路由匹配( / NA0 ):

路线不匹配( / NN0 ):

路由匹配( / NFG ):

路线不匹配( / FFG ):

我猛然一惊。这里的路由code,万一它不是在截图RouteDebug表明确:

  routes.MapRoute(
            NonBrandedSlideshow
            N(编号),
            MVC.Slideshow.NonBranded(),空,
            新{ID = Settings.Base32Regex}
        );        routes.MapRoute(
            FullSlideshow
            F(编号),
            MVC.Slideshow.Full(),空,
            新{ID = Settings.Base32Regex}
        );        routes.MapRoute(
            CompactSlideshow
            C(编号),
            MVC.Slideshow.Compact(),空,
            新{ID = Settings.Base32Regex}
        );        routes.MapRoute(
            FlexibleSlideshow
            ×(编号),
            MVC.Slideshow.Flexible(),空,
            新{ID = Settings.Base32Regex}
        );        routes.MapRoute(
            Html5Slideshow
            H(编号),
            MVC.Slideshow.NonBrandedHtml5(),空,
            新{ID = Settings.Base32Regex}
        );

我要在这里指出,我使用 T4MVC (参见2.2.5节),而这些图路线方法是通过添加T4MVC扩展。我使用的图路线方法等同于标准方法,我已经使用非T4MVC 图路线方法尝试具有相同的结果:

  routes.MapRoute(
            Html5Slideshow
            H(编号),
            新{控制器=幻灯片,行动=NonBrandedHtml5},
            新{ID = Settings.Base32Regex}
        );

下面是Base32Regex,虽然我有没有这个约束试了一下(我用的假设I和O的Base32实施为1和0,例如)。

 公共静态部分类设置
{
    公共静态字符串Base32Regex
    {
        得到{@[0-9ABCDEFGHJKMNPQRSTVWXYZ] +; }
    }
}


解决方案

好吧,我就像猛然一惊。我进行了一些其他的测试,据我所看到的,这必须在当路由参数之前不断有相同的重复字符的路线进行检查的方式的一些bug。其他一些令人难以置信的例子:

 NN(编号)
路由匹配(/ nna0)
路线不匹配(/ nnn0)NNN(编号)
路由匹配(/ nnna0)
路线不匹配(/ nnnn0)

只要我做出不断的不重复相同的字符,一切都很好。

 MN(编号)
路由匹配(/ mna0)
路由匹配(/ mnn0)
路由匹配(/ mnmn)

这可能不是你正在寻找什么。但是,鉴于形势的怪异,这是我能想出的唯一的事。常数添加到约束和从链接中删除。然后在您的控制器(这是我不喜欢的部分),您将需要从id参数删除该常数。希望这个作品,或至少帮助引发另一种解决方案。

  routes.MapRoute(
    NonBrandedSlideshow
    {ID},
    MVC.Slideshow.NonBranded(),空,
    新{ID =N+ Settings.Base32Regex}
);

更新:

我想这是一个已知问题,感谢@ MAX-塘路

I'm having some trouble getting routes to match.

I am using base-32 encoded int's as short links to slideshows in a web app. There are 5 different versions of each slideshow, and I am using an initial letter to distinguish between each version.

The routes always match, except when the first character of the base-32 encoded int is the same as the character designating the slideshow version. This anomaly exists for all 5 prefix letters: n, f, c, x, and h.

What about the first two characters being the same makes these routes not match? I'm at a loss to understand what's going on here (when the routes don't match, they simply fall through to the default).

Route Matches (/na0):

Route Doesn't Match (/nn0):

Route Matches (/nfg):

Route Doesn't Match (/ffg):

I'm boggled. Here's the routing code, in case it isn't clear in the RouteDebug tables in the screenshots:

        routes.MapRoute(
            "NonBrandedSlideshow",
            "n{id}",
            MVC.Slideshow.NonBranded(), null,
            new { id = Settings.Base32Regex }
        );

        routes.MapRoute(
            "FullSlideshow",
            "f{id}",
            MVC.Slideshow.Full(), null,
            new { id = Settings.Base32Regex }
        );

        routes.MapRoute(
            "CompactSlideshow",
            "c{id}",
            MVC.Slideshow.Compact(), null,
            new { id = Settings.Base32Regex }
        );

        routes.MapRoute(
            "FlexibleSlideshow",
            "x{id}",
            MVC.Slideshow.Flexible(), null,
            new { id = Settings.Base32Regex }
        );

        routes.MapRoute(
            "Html5Slideshow",
            "h{id}",
            MVC.Slideshow.NonBrandedHtml5(), null,
            new { id = Settings.Base32Regex }
        );

I should note here that I am using T4MVC (see section 2.2.5), and these MapRoute methods are extensions added by T4MVC. The MapRoute methods I am using are equivalent to the standard methods, and I have tried using the non-T4MVC MapRoute method with the same result:

        routes.MapRoute(
            "Html5Slideshow",
            "h{id}",
            new { controller = "Slideshow", action = "NonBrandedHtml5" },
            new { id = Settings.Base32Regex }
        );

Here is the Base32Regex, though I have tried it with and without this constraint (the Base32 implementation I am using will assume I and O are 1 and 0, for example).

public static partial class Settings
{
    public static string Base32Regex
    {
        get { return @"[0-9ABCDEFGHJKMNPQRSTVWXYZ]+"; }
    }
}

解决方案

Well, I am just as boggled. I performed some other tests and as far as I can see, this has to be some bug in the way the routes are checked when the constant before the route parameter has the same repeated character. Some other boggling examples:

"nn{id}"
route matches (/nna0)
route doesn't match (/nnn0)

"nnn{id}"
route matches (/nnna0)
route doesn't match (/nnnn0)

as soon as i make the constant not repeat the same character, all is well

"mn{id}"
route matches (/mna0)
route matches (/mnn0)
route matches (/mnmn)

This may not be exactly what you are looking for. But given the oddity of the situation, it was the only thing I could come up with. Add the constant to the constraint and remove it from the url. Then in your controller (this is the part I didn't like) you will need to remove that constant from the id parameter. Hope this works, or at the least help spark another solution.

routes.MapRoute(
    "NonBrandedSlideshow",
    "{id}",
    MVC.Slideshow.NonBranded(), null,
    new { id = "n"+Settings.Base32Regex }
);

UPDATE:

I guess this is a known issue, thanks @max-toro

这篇关于为什么不会这个路由匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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