我看了很多帖子,和我没有看到我的mystake。

一些机构可以帮我请。

有是我的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) %>

我得到这个URL

HTTP://本地主机:8458 /帐户/ EditProfile用户名= cboivin

如果我尝试直接调用链接等 HTTP://本地主机:8458 /帐户/ EditProfile / cboivin

不工作,...

有是我的方法在我的AccountController

 public ActionResult EditProfile(string username)
        {

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

我不知道哪里是我的错误。一些机构可以帮我吗?感谢。

有帮助吗?

解决方案

路线读自上而下,你的“一网打尽”一般路线必须是最后一次。

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
        );

其他提示

尝试移除:

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

和记住更多的一般途径应该是在你的路由表的底部,而更为具体的路线应该来在上面。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top