REGISTERROUTES NOT WORKING IN MVC5

Brad Pitt

Total Post:61

Points:429
Posted by  Brad Pitt
 1203  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. Pawan Shukla

    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 Mar-17-2016 04:26:48 AM

Answer

NEWSLETTER

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