Admin/User라는 두 영역으로 구성된 프로젝트가 있습니다.MVC 역할 기반 라우팅
관리의 기본 경로는 /관리/홈/색인과 사용자의 기본 경로는 /사용자/홈/색인입니다.
는 자신의 홈 URL이 /프로필/색인처럼 보이게하지만 콘텐츠를 표시 할 수 있도록 라우팅을 구현하는 것이 가능 /관리/홈 관리자를위한/인덱스와 사용자 /사용자/홈/색인 ?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",
"Profile/{action}",
new { area = AreaName, controller = "Home", action = "Index" },
new { RoleConstraint = new Core.RoleConstraint() },
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 방식이 아니다. 아무도 그것을 올바르게하는 방법을 압니까?