配置asp.net mvc路由

时间:2014-04-17 08:46:35

标签: asp.net routing asp.net-mvc-5

我在RouteConfig.cs中使用此代码进行路由:

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

现在我要更改它,如果网址为"<domain>/Saman/Profile",我应该为username"Saman"的用户加载个人资料页面。

1 个答案:

答案 0 :(得分:0)

实际上你必须在默认路由之前给出配置文件路由。一旦它发现它将使用第一条路由,它会查找配置文件。我希望这可以工作。

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