Asp.net mvc MVC4默认路由

Asp.net mvc MVC4默认路由,asp.net-mvc,asp.net-mvc-4,routes,Asp.net Mvc,Asp.net Mvc 4,Routes,我有以下两条路径,当用户登陆主页时,它抛出404。有什么明显的东西我不知道吗?我想让他们去主控室 routes.MapRoute( name: "Default", url: "Home/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },

我有以下两条路径,当用户登陆主页时,它抛出404。有什么明显的东西我不知道吗?我想让他们去主控室

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

        routes.MapRoute(
            name: "Organization",
            url: "{organization}/{controller}/{action}/{id}",
            defaults: new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional },
            namespaces: new[] { "Coin.Web.Controllers" }
提前谢谢

是的,路由/将错过默认路由,因为它需要在URL中以您设置它的方式使用/Home段,并且它也将错过组织路由,因为您没有定义默认组织。这就是你得到404的原因

您可以通过为主页显式添加路由来修复此问题:

    routes.MapRoute(
        name: "Home",
        url: "",
        defaults: new { controller = "Home", action = "Index" },
        namespaces: new[] { "Coin.Web.Controllers" }
    );

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

    routes.MapRoute(
        name: "Organization",
        url: "{organization}/{controller}/{action}/{id}",
        defaults: new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional },
        namespaces: new[] { "Coin.Web.Controllers" }

仅供参考-通常最好先选择更具体的路线,然后再选择不太具体的路线。也就是说,组织路线应该先走,而默认路线应该保持不变。但是,您需要定义一个明确的段或约束,以强制组织路由上的未命中,或使用多个组织路由来实现这一点。

如果不知道您试图使用的url是什么,则很难确定是什么错误。