Asp.Net路由重写为用户名或者ID

有一个需求如下:指定某个Area的路由(Area:Wx)在其后面添加用户名或者ID作为URL参数,即像下面的样子:

/Wx/xiaoming/

/Wx/xiaoming/photo

/Wx/xiaoming/photo/manage?oid=34

 

这样的话修改一下路由就好了,如下:

 

context.MapRoute(
  "Wx_rester_with_id2",
  "Wx/{rid}/{controller}/{action}/",
  new { controller = "Rester", action = "Index", rid = "" }
);

 获取参数的话正常获取就可以了,即:

public ActionResult Lili(long id)
{
  var rid = this.RouteData.Values["rid"];
  return Content("user yes:" + id);
}

 

posted @ 2017-02-21 10:34  朝野布告  阅读(269)  评论(0编辑  收藏  举报