c#mvc路由配置动态用户名下属站点

1.

App_Start\RouteConfig.cs
routes.MapRoute(
name: "User",
url: "User/{username}/{action}",
defaults: new { controller = "User", action = "Index", username = UrlParameter.Optional },
namespaces: new string[] { "Web.Controllers" }
);

 

2.

Web.Controllers.UserController:Controller

  public ActionResult Index(){return View();}

3.

Views\User\Index.cshtml

 

4.测试

http://localhost/User/aaa/Index

 

posted @ 2017-07-28 09:45  以函  阅读(127)  评论(0编辑  收藏  举报