我有一个项目有2个区域/ Admin和/ User。
Admin的默认路由为/ Admin / Home / Index,用户的默认路由为/ User / Home / Index。
是否可以实现路由以使其家乡网址看起来像/ Profile / Index,但是要显示/ Admin / Home / Index的用户管理员和/ User / Home / Index的内容?
UPD
最后找出如何做到这一点
- context.MapRoute(
- "Admin","Profile/{action}",new { area = AreaName,controller = "Home",action = "Index" },new { RoleConstraint = new Core.RoleConstraint() },new[] { "MvcApplication1.Areas.Admin.Controllers" }
- );
- ...
- context.MapRoute(
- "User",new[] { "MvcApplication1.Areas.User.Controllers" }
- );
- public class RoleConstraint : IRouteConstraint
- {
- public bool Match(HttpContextBase httpContext,Route route,string parameterName,RouteValueDictionary values,RouteDirection routeDirection)
- {
- string roleName = db.GetRoleByUserName(httpContext.User.Identity.Name);
- string areaName = route.Defaults["area"].ToString();
- return areaName == roleName;
- }
- }
它的作品,但对我来说,这不是MVC的方式。有人知道怎么做吗?