Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make routing in asp.net mvc domainname/username so each user has his "username" like facebook does

How to make routing in asp.net mvc domainname/username so each user has his "username" like facebook does

Thank you in advance!

like image 329
Sergey Avatar asked Jan 16 '23 01:01

Sergey


2 Answers

You just use the username part as the {id} element, and have a default {action}.

like image 160
stevethethread Avatar answered Jan 19 '23 01:01

stevethethread


Try This

      routes.MapRoute(
           "users", // Route name
           "{username}", // URL with parameters
           new { controller = "Home", action = "User" } // Parameter defaults
       );

and this will be first MapRoute, and action would be like

    public ActionResult User(string username)
    {
        return View();
    }
like image 23
Yograj Gupta Avatar answered Jan 19 '23 00:01

Yograj Gupta