0

我读了很多帖子,但我没有看到我的赌注。

一些身体可以帮助我吗?

有我的 global.asax

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");                
           routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
           routes.MapRoute("UserName", "Account/{action}/{username}",
          new { action = "EditProfile", controller = "Account" });   

        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }

当我使用

<%= Html.ActionLink("Edit Account", "EditProfile", "Account", new { username = Html.Encode(Page.User.Identity.Name) },null) %>

我得到了这个网址

http://localhost:8458/Account/EditProfile?username=cboivin

如果我尝试像 http://localhost:8458/Account/EditProfile/cboivin一样直接调用 url

不工作...

我的 AccountController 中有我的方法

 public ActionResult EditProfile(string username)
        {

            return View(ServiceFactory.UserAccount.GetUserByUserName(new GetUserByUserNameArgs(username)));
        }

我不知道我的错误在哪里。一些身体可以帮助我吗?谢谢。

4

2 回答 2

6

路线是自上而下阅读的,您的“包罗万象”一般路线需要放在最后。

routes.MapRoute("UserName", "Account/{action}/{username}",
          new { action = "EditProfile", controller = "Account" });


routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );
于 2009-12-06T15:48:34.503 回答
0

尝试删除:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

请记住,更通用的路由应该放在路由表的底部,而更具体的路由应该放在最上面。

于 2009-12-06T15:55:04.273 回答