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


C# ClaimsPrincipal.IsInRole方法代码示例

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


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

示例1: PartialWithRole

 public static IHtmlContent PartialWithRole(this IHtmlHelper helper, string partialName, object model, ClaimsPrincipal user, UserRoleEnum userRole)
 {
     if (user.IsInRole(userRole.ToString()))
     {
         return helper.Partial(partialName, model: model);
     }
     else
     {
         return helper.Raw(string.Empty);
     }
 }
开发者ID:psmyrdek,项目名称:it-learning,代码行数:11,代码来源:HtmlHelperExtensions.cs

示例2: GetRole

        private Claim GetRole(ClaimsPrincipal incomingPrincipal)
        {
            var sid = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);

            if (incomingPrincipal.IsInRole(sid.Value))
            {
                return new Claim(ClaimTypes.Role, "Operator");
            }
            else
            {
                return new Claim(ClaimTypes.Role, "User");
            }
        }
开发者ID:Rameshcyadav,项目名称:Thinktecture.IdentityModel.45,代码行数:13,代码来源:ClaimsTransformer.cs

示例3: CheckNamesAndRole

        /// <summary>
        /// First string is expected, others are not.
        /// </summary>
        /// <param name="names"></param>
        /// <param name="roles"></param>
        private void CheckNamesAndRole(string[] names, string[] roles, ClaimsPrincipal principal, string expectedNameClaimType = ClaimsIdentity.DefaultNameClaimType, string expectedRoleClaimType = ClaimsIdentity.DefaultRoleClaimType)
        {
            ClaimsIdentity identity = principal.Identity as ClaimsIdentity;
            Assert.AreEqual(identity.NameClaimType, expectedNameClaimType);
            Assert.AreEqual(identity.RoleClaimType, expectedRoleClaimType);
            Assert.IsTrue(principal.IsInRole(roles[0]));
            for (int i = 1; i < roles.Length; i++)
            {
                Assert.IsFalse(principal.IsInRole(roles[i]));
            }

            Assert.AreEqual(identity.Name, names[0]);
            for (int i = 1; i < names.Length; i++)
            {
                Assert.AreNotEqual(identity.Name, names[i]);
            }
        }
开发者ID:richardschneider,项目名称:azure-activedirectory-identitymodel-extensions-for-dotnet,代码行数:22,代码来源:CreateAndValidateTokens.cs

示例4: CheckForRoles

        /// <summary>
        /// First role is expected, others are not.
        /// </summary>
        /// <param name="names"></param>
        /// <param name="roles"></param>
        private void CheckForRoles(string[] expectedRoles, string[] unexpectedRoles, ClaimsPrincipal principal, string expectedRoleClaimType = ClaimsIdentity.DefaultRoleClaimType)
        {
            ClaimsIdentity identity = principal.Identity as ClaimsIdentity;
            Assert.AreEqual(identity.RoleClaimType, expectedRoleClaimType);
            for (int i = 1; i < expectedRoles.Length; i++)
            {
                Assert.IsTrue(principal.IsInRole(expectedRoles[i]));
            }

            for (int i = 1; i < unexpectedRoles.Length; i++)
            {
                Assert.IsFalse(principal.IsInRole(unexpectedRoles[i]));
            }
        }
开发者ID:vebin,项目名称:azure-activedirectory-identitymodel-extensions-for-dotnet,代码行数:19,代码来源:CreateAndValidateTokens.cs

示例5: GetVoteMatchs

 public List<VoteMatchViewModel> GetVoteMatchs(ClaimsPrincipal user)
 {
     return BddContext
         .Matchs
         .Where(m => (m.Equipe1.Contains("HORGUES ODOS") || m.Equipe2.Contains("HORGUES ODOS")) && (m.VoteStatut == 1 || m.VoteStatut == 2 || (user.IsInRole("Contributor") && m.VoteStatut == 0 && m.Date < DateTime.Now)))
         .Select(x => new VoteMatchViewModel() { MatchId = x.Id, Date = x.Date, Equipe1 = x.Equipe1, Equipe2 = x.Equipe2, Statut = x.VoteStatutEnum, Competition = x.Competition.Nom })
         .OrderBy(x => x.Date)
         .ToList();
 }
开发者ID:orome656,项目名称:HOFCServerNet,代码行数:9,代码来源:MatchService.cs


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