我在RouteConfig.cs
中使用此代码进行路由:
routes.MapRoute("Default", "", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
现在我要更改它,如果网址为"<domain>/Saman/Profile"
,我应该为username
为"Saman"
的用户加载个人资料页面。
答案 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 }
);