【问题标题】:Multiple routes in mvc,netmvc,net中的多条路由
【发布时间】:2013-01-05 00:10:54
【问题描述】:

我的 mvc 应用程序中有多个路由。我想知道应用程序中的多个路由对性能不利吗?

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                "Faq",
                "Faq/{action}",
                new { controller = "Faq", action = "Index" }
                );
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                "PostArchive",
                "Post/{action}",
                new { controller = "Post", action = "PostArchive" }
                );
            routes.MapRoute(
                "LogOn",
                "Account/{action}",
                new { controller = "Account", action = "LogOn" }
                );
            routes.MapRoute(
                "Localization",
                "{lang}/{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional, lang = UrlParameter.Optional } // Parameter defaults
                );

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

            routes.MapRoute(
                name: "Post",
                url: "{lang}/{controller}/{action}/{id}/{Title}",
                defaults: new { controller = "Post", action = "Index", id = UrlParameter.Optional, Title = UrlParameter.Optional },
                namespaces: new[] { "MVCTemplateProject.Controllers" }
                );

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 routes


    【解决方案1】:

    不,路线检查快速高效。

    大多数网站只有很少或只有一条路线。

    其他网站有 30 多条路线。根据我的经验,拥有 30 条不同路线的网站在性能上没有明显的滞后。

    【讨论】:

      【解决方案2】:

      Sam Saffron wrote an interesting blog article 关于路由性能 - 特别是使用正则表达式约束的路由,以及路由的排序。绝对值得一读,特别是如果您考虑到他通过那些相对简单的实施技术实现的性能改进。

      【讨论】:

        猜你喜欢
        • 2012-01-26
        • 2011-11-17
        • 1970-01-01
        • 2014-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-03
        • 2018-08-09
        相关资源
        最近更新 更多