RegisterRoutes not working in mvc5

Total Post:61

Points:429
 1541  View(s)
Ratings:
Rate this:

Anyone know why this is not working, i have googled it but nothing seems to work. All i want to do is allow www.abcdefg.com/username to map to a profile page but it does not work and i can't find out why.

public static void RegisterRoutes(RouteCollection routes)
        {
         routes.MapRoute(
        "Default",     // Route name
        "{controller}/{action}/{id}",   // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        , new { controller = @"(admin|help|profile|Settings)" } // Constraints
    );
                routes.MapRoute(
                  "Users",
                  "{username}",
                  new { controller = "Home", action = "Index", username = "" });
            }

  1. Post:29

    Points:203
    Re: RegisterRoutes not working in mvc5

    You must adding the default route as the last route


    public static void RegisterRoutes(RouteCollection routes)
            {
             routes.MapRoute(
               "Users",
               "{username}",
               new { controller = "Home", action = "Index", username = "" });
             routes.MapRoute(
               "Default",     // Route name
               "{controller}/{action}/{id}",       // URL with parameters
               new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
               , new { controller = @"(admin|help|profile|Settings)" } // Constraints
        );

      Modified On Apr-06-2018 11:58:39 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!