本文整理汇总了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);
}
}
示例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");
}
}
示例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();
}