Home > DeveloperSection > Forums > RegisterRoutes not working in mvc5
Brad Pitt
Brad Pitt

Total Post:61

Points:429
Posted on    November-20-2014 10:15 PM

 ASP.NET MVC ASP.Net  Mvc5 
Ratings:


 1 Reply(s)
 833  View(s)
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 = "" });

            }



Pawan Shukla
Pawan Shukla

Total Post:29

Points:203
Posted on    November-21-2014 12:17 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick