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


C# IPrincipal.IsInRole方法代码示例

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


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

示例1: IsZoneLeadOrAdminOrSuperAdmin

 /// <summary>
 /// Returns true if the user is Moderator, Zone Lead, Admin or SuperAdmin
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public static bool IsZoneLeadOrAdminOrSuperAdmin(IPrincipal user)
 {
     return
         user.IsInRole(RoleType.Administrator.ToString())
         || user.IsInRole(RoleType.ZoneLeader.ToString())
         || user.IsInRole(RoleType.SuperAdministrator.ToString());
 }
开发者ID:LordBlacksun,项目名称:Allegiance-Community-Security-System,代码行数:12,代码来源:Authorization.cs

示例2: GetVisibleUnits

		public List<string> GetVisibleUnits(string courseId, IPrincipal user)
		{
			var canSeeEverything = user.IsInRole(LmsRoles.Tester) || user.IsInRole(LmsRoles.Admin) || user.IsInRole(LmsRoles.Instructor);
			if (canSeeEverything)
				return courseManager.GetCourse(courseId).Slides.Select(s => s.Info.UnitName).Distinct().ToList();
			return db.Units.Where(u => u.CourseId == courseId && u.PublishTime <= DateTime.Now).Select(u => u.UnitName).ToList();
		}
开发者ID:fakefeik,项目名称:uLearn,代码行数:7,代码来源:UnitsRepo.cs

示例3: IsSaveEnabled

        public bool IsSaveEnabled(IPrincipal user)
        {
            if (!CustomRoleEditingEnabled)
                return false;

            if (IsSystemRole)
                return false;

            if(user.IsInRole(Permissions.AddUsers.ToString()) || user.IsInRole(Permissions.EditUsers.ToString()))
            {
                return true;
            }

            return false;
        }
开发者ID:mnasif786,项目名称:Business-Safe,代码行数:15,代码来源:UserRolePermissionsViewModel.cs

示例4: GetLevel

 private static AdminLevels GetLevel(IPrincipal principal){
     if (principal.IsInRole(RoleConstants.AccessAllData))
     {
         return AdminLevels.AllData;
     }
     else if (principal.IsInRole(RoleConstants.AccessInstitution))
     {
         return AdminLevels.InstitutionAdmin;
     }
     else if (principal.IsInRole(RoleConstants.AccessDepartment))
     {
         return AdminLevels.DepartmentAdmin;
     }
     return AdminLevels.None;
 }
开发者ID:mcshaz,项目名称:SimPlanner,代码行数:15,代码来源:CurrentPrincipal.cs

示例5: IsUserAllowed

        public override CustomAuthorizationRuleAction IsUserAllowed(IPrincipal user)
        {
            if (user != null && user.Identity.IsAuthenticated && user.IsInRole(Value))
                return Action;

            return CustomAuthorizationRuleAction.NotExisted;
        }
开发者ID:chiganock,项目名称:VtecTeamFlasher,代码行数:7,代码来源:RoleRule.cs

示例6: AdminMenuItem

        /// <summary>
        /// Renders an admin menu item on the navbar if the user is an admin
        /// </summary>
        /// <param name="helper">Extends the HtmlHelper class</param>
        /// <param name="user">The current user</param>
        /// <returns>Renders a list item to add to the menu bar for an admin, if the user is a member
        /// of the admin role. Otherwise, an emptyh string is returned.</returns>
        public static string AdminMenuItem(this HtmlHelper helper, IPrincipal user)
        {
            string menuItem = string.Empty;

            if (helper == null)
            {
                throw new ArgumentNullException("helper");
            }

            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (user.IsInRole(FrogBlogger.Web.Helpers.Roles.Admin))
            {
                Guid blogId = BlogUtility.GetBlogId();

                using (IDataRepository<Author> repository = new DataRepository<Author>())
                {
                    if (repository.Fetch(a => a.BlogId == blogId).Any())
                    {
                        menuItem = String.Format("<li>{0}</li>", helper.ActionLink("Admin", "Index", "Admin"));
                    }
                }
            }

            return menuItem;
        }
开发者ID:senfo,项目名称:FrogBlogger,代码行数:36,代码来源:NavMenuHelper.cs

示例7: GetPrincipal

        /// <summary>
        /// Presents a logon screen which accepts a username/password.
        /// </summary>
        /// <returns></returns>
        public IPrincipal GetPrincipal()
        {
            if (principal != null) {
                return principal;
            }

            LogOnScreen logon = new LogOnScreen();
            #if DEBUG
            logon.HintVisible = true;
            #endif
            bool? res = logon.ShowDialog();
            if (!res ?? true) {
                // User clicked cancel.
                return null;
            } else if (userProvider.Authenticate(logon.UserName, logon.Password)) {
                // Credentials were authenticated.
                GenericIdentity ident = new GenericIdentity(logon.UserName);
                principal = new GenericPrincipal(ident, userProvider.GetRoles(logon.UserName));

                if (!principal.IsInRole(userProvider.ApplicationRole)) {
                    throw new AuthenticationException();
                }

                return principal;
            } else {
                // Invalid username/password.
                throw new InvalidCredentialException();
            }
        }
开发者ID:wcrooy,项目名称:cwpfsamples,代码行数:33,代码来源:SimpleSecurityService.cs

示例8: IsReadAllowed

 public bool IsReadAllowed(IPrincipal oPrincipal)
 {
     foreach (string strRoles in ReadAllowed)
         if (oPrincipal.IsInRole(strRoles))
             return true;
     return false;
 }
开发者ID:trevorpower,项目名称:tadmap,代码行数:7,代码来源:RolesForProperty.cs

示例9: IsInRoles

 /// <summary>Asks the user if it is in any of the roles.</summary>
 /// <param name="user">The user to check.</param>
 /// <param name="roles">The roles to look for.</param>
 /// <returns>True if the user is in any of the given roles.</returns>
 public static bool IsInRoles(IPrincipal user, IEnumerable<string> roles)
 {
     foreach (string role in roles)
         if (user.IsInRole(role))
             return true;
     return false;
 }
开发者ID:spmason,项目名称:n2cms,代码行数:11,代码来源:PermissionMap.cs

示例10: IsWriteDenied

 public bool IsWriteDenied(IPrincipal oPrincipal)
 {
     foreach (string strRoles in WriteDenied)
         if (oPrincipal.IsInRole(strRoles))
             return true;
     return false;
 }
开发者ID:trevorpower,项目名称:tadmap,代码行数:7,代码来源:RolesForProperty.cs

示例11: IsSupervisor

		/// <summary>
		/// 是否是超级管理员
		/// </summary>
		/// <param name="principal"></param>
		/// <returns></returns>
		public static bool IsSupervisor(IPrincipal principal)
		{
			bool result = false;

			if (principal != null)
			{
				result = (bool)ObjectContextCache.Instance.GetOrAddNewValue(principal, (cache, key) =>
					{
						bool innerResult = false;

						string roleName = Configuration.AUConfigurationSection.GetConfig().MasterRoleFullCodeName;

						if (roleName.IsNotEmpty())
						{
							IRole role = new OguRole(roleName);

							if (role.ObjectsInRole.Count == 0)
								innerResult = true;
							else
								innerResult = principal.IsInRole(roleName);
						}
						else
							innerResult = true;

						cache.Add(key, innerResult);

						return innerResult;
					});
			}

			return result;
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:37,代码来源:AUPrincipalExtension.cs

示例12: isInOverideRole

        protected virtual bool isInOverideRole(IPrincipal thisUser)
        {
            if (thisUser == null)
                throw new ArgumentNullException("thisUser", "thisUser is null.");

            return thisUser.IsInRole("administrator");
        }
开发者ID:justinobney,项目名称:mindbody-api,代码行数:7,代码来源:RequireAuthenticationAttribute.cs

示例13: IsOwner

 public bool IsOwner(IPrincipal user)
 {
     if (user == null || user.Identity == null)
     {
         return false;
     }
     return user.IsInRole(Constants.AdminRoleName) || Owners.Any(u => u.Username == user.Identity.Name);
 }
开发者ID:N198,项目名称:NugetGallery21-DeleteMe,代码行数:8,代码来源:ListPackageItemViewModel.cs

示例14: GetFucProposal

        public HttpResponse GetFucProposal(IPrincipal principal)
        {
            var props = _repo.GetAll().Where(p => p.State == AbstractEntity<long>.Status.Pending);

            return new HttpResponse(HttpStatusCode.OK,
                new ProposalView(principal.IsInRole(Roles.Utilizador) ?
                                    props.Where(p => p.Owner.Equals(principal.Identity.Name)) :
                                    props));
        }
开发者ID:LuisLoureiro,项目名称:isel-leic-pi-1112si,代码行数:9,代码来源:ProposalController.cs

示例15: IsAccessAllowed

        public static bool IsAccessAllowed(string Controller, string Action, IPrincipal User, string IP)
        {
            if (Controller == "Login")
                return true;

            if (Controller == "Dashboard" && User.IsInRole("1"))
                return true;

            return false;
        }
开发者ID:aminul,项目名称:NewTest,代码行数:10,代码来源:PageAccessManager.cs


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