本文整理汇总了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;
}