当前位置: 首页>>代码示例>>C#>>正文


C# HttpContext.CorePrincipal方法代码示例

本文整理汇总了C#中System.Web.HttpContext.CorePrincipal方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContext.CorePrincipal方法的具体用法?C# HttpContext.CorePrincipal怎么用?C# HttpContext.CorePrincipal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpContext的用法示例。


在下文中一共展示了HttpContext.CorePrincipal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitializeMenu

        private static Dictionary<String, IEnumerable<IMenuItem>> InitializeMenu(HttpContext context, HtmlHelper html)
        {
            var menuItems = new Dictionary<String, IEnumerable<IMenuItem>>();
            var permissionService = ServiceLocator.Current.GetInstance<IPermissionCommonService>();
            var user = context.CorePrincipal();
            bool isUsersAllowed = permissionService.IsAllowed((int)BaseEntityOperations.Manage, user, typeof(User), null);
            bool isUserGroupsAllowed = permissionService.IsAllowed((int)BaseEntityOperations.Manage, user, typeof(UserGroup), null);
            bool isRolesAllowed = permissionService.IsAllowed((int)BaseEntityOperations.Manage, user, typeof(Role), null);
            if (isUsersAllowed || isUserGroupsAllowed || isRolesAllowed)
            {
                var usersMenuItem = new List<IMenuItem>();
                if (isUsersAllowed)
                {
                    usersMenuItem.Add(new ActionLink<UserController>(html.Translate(".Users"), Links.Content.Images.Admin.ico1_png, c => c.Index()));
                }
                if (isUserGroupsAllowed)
                {
                    usersMenuItem.Add(new ActionLink<UserGroupController>(html.Translate(".UserGroups"), Links.Content.Images.Admin.ico2_png, c => c.Index()));
                }
                if (isUsersAllowed)
                {
                    usersMenuItem.Add(new ActionLink<RoleController>(html.Translate(".Roles"), Links.Content.Images.Admin.ico3_png, c => c.Index()));
                }
                menuItems.Add(html.Translate(".AccountsAndPermissions"), usersMenuItem);
            }

            var siteSettingsAccess = permissionService.IsAllowed((int)BaseEntityOperations.Manage, user, typeof(SiteSettings), null);
            var pluginsAccess = permissionService.IsAllowed((int)BaseEntityOperations.Manage, user, typeof(Plugin), null);
            var pagesAccess = permissionService.IsAllowed((int)BaseEntityOperations.Manage, user, typeof(Page), null);
            var pagesTemplateAccess = permissionService.IsAllowed((int)BaseEntityOperations.Manage, user, typeof(PageTemplate), null);
            if (siteSettingsAccess || pluginsAccess || pagesAccess || pagesTemplateAccess)
            {
                var administrationMenuItem = new List<IMenuItem>();

                if (siteSettingsAccess)
                {
                    administrationMenuItem.Add(new ActionLink<SiteSettingsController>(html.Translate(".SiteSettings"), Links.Content.Images.Admin.ico1_png, c => c.Show()));
                }
                if (pluginsAccess)
                {
                    administrationMenuItem.Add(new ActionLink<ModuleController>(html.Translate(".Modules"), Links.Content.Images.Admin.ico5_png, c => c.Index()));
                    administrationMenuItem.Add(new ActionLink<WidgetController>(html.Translate(".Widgets"), Links.Content.Images.Admin.ico6_png, c => c.Index()));
                }
                if (pagesAccess)
                {
                    administrationMenuItem.Add(new ActionLink<PageController>(html.Translate(".Pages"), Links.Content.Images.Admin.ico6_png, c => c.Index()));
                    administrationMenuItem.Add(new ActionLink<PageTemplateController>(html.Translate(".PageTemplates"), Links.Content.Images.Admin.ico6_png, c => c.Index()));
                }

                menuItems.Add(html.Translate(".Administration"), administrationMenuItem);
            }

            var pluginHelper = ServiceLocator.Current.GetInstance<IPluginHelper>();
            var usersMenuItem1 = (from verb in Application.GetVerbsForCategory("AdminModules")
                                  where pluginHelper.IsPluginEnabled(verb.ControllerPluginIdentifier) && verb.IsAllowed(context.CorePrincipal())
                                  select new RouteLink(verb.Name, Links.Content.Images.Admin.ico3_png, verb.RouteName)).Cast<IMenuItem>().ToList();

            if (usersMenuItem1.Count > 0)
                menuItems.Add(html.Translate(".Modules"), usersMenuItem1);

            return menuItems;
        }
开发者ID:coreframework,项目名称:Core-Framework,代码行数:62,代码来源:MenuExtension.cs


注:本文中的System.Web.HttpContext.CorePrincipal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。