Asp.net mvc 2 Asp.net Mvc 2如何重新路由到www.example.com/my-profile

Asp.net mvc 2 Asp.net Mvc 2如何重新路由到www.example.com/my-profile,asp.net-mvc-2,Asp.net Mvc 2,我想将此地址www.exmaple.com/my-profile重新路由到mvc应用程序中的配置文件控制器。这里有my global.aspx,您可以看到默认路由是 routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}/", // URL with parameters new { controller = "Hom

我想将此地址www.exmaple.com/my-profile重新路由到mvc应用程序中的配置文件控制器。这里有my global.aspx,您可以看到默认路由是

routes.MapRoute(
                "Default", // Route name
                 "{controller}/{action}/{id}/", // URL with parameters
               new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
                );
这是我试图用来重新路由到www.exmaple.com/my-profile的Maproute

routes.MapRoute(
                "Profile", // Route name
                "{profile_name}/", // URL with parameters
                new { controller = "Portfolio", action = "Index", page = UrlParameter.Optional } // Parameter defaults
            );
routes.MapRouteLowercase(
                "Profile", // Route name
                "profile/{profile_name}/", // URL with parameters
                new { controller = "Portfolio", action = "Index", page = UrlParameter.Optional } // Parameter defaults
            );
问题是,当我键入www.exmaple.com/profile时,它试图将我指向默认的maproute,而不是我指定的maproute

但当我能做到这一点时www.example.com/profile/my-profile

routes.MapRoute(
                "Profile", // Route name
                "{profile_name}/", // URL with parameters
                new { controller = "Portfolio", action = "Index", page = UrlParameter.Optional } // Parameter defaults
            );
routes.MapRouteLowercase(
                "Profile", // Route name
                "profile/{profile_name}/", // URL with parameters
                new { controller = "Portfolio", action = "Index", page = UrlParameter.Optional } // Parameter defaults
            );
它工作正常,但我不想在我的个人资料之前添加个人资料。我希望它能像facebook.com/my-profile或youtube.com/my-profile那样工作

有人知道我是如何做到这一点的吗?我已经寻找解决方案两个多月了(断断续续)


谢谢

如果我没记错,您的路由将返回URL的第一个匹配模式。我希望在您的情况下,您的URL首先匹配您的默认模式


将更具体的路线移到“默认”路线上方,看看这是否有帮助。

嗨,我尝试过将它们切换过来,但都没用。它试图将所有遵循“{}/{}/”模式的URL路由到我的个人资料页面。