大佬教程收集整理的这篇文章主要介绍了asp.net-mvc – 基于MVC角色的路由,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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的方式。有人知道怎么做吗?
以上是大佬教程为你收集整理的asp.net-mvc – 基于MVC角色的路由全部内容,希望文章能够帮你解决asp.net-mvc – 基于MVC角色的路由所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。