views:

67

answers:

2

I read a lot of post, and i dont see my mystake.

Can some body help me please.

There is my 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);
        }

When i use

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

I got this url

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

if i try to call the url directly like http://localhost:8458/Account/EditProfile/cboivin

not work to ...

There is my method in my AccountController

 public ActionResult EditProfile(string username)
        {

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

I dont know where is my mistake. Can some body help me ? Thanks.

+5  A: 

Routes are read top down, your "catch all" general route needs to be last.

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
        );
Paul Creasey
Thanks very much
Cédric Boivin
A: 

Try removing:

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

And remember more general routes should be at the bottom of your routing table, while more specific routes should come on top.

Colour Blend