本文整理汇总了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());
}
示例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();
}
示例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;
}
示例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;
}
示例5: IsUserAllowed
public override CustomAuthorizationRuleAction IsUserAllowed(IPrincipal user)
{
if (user != null && user.Identity.IsAuthenticated && user.IsInRole(Value))
return Action;
return CustomAuthorizationRuleAction.NotExisted;
}
示例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;
}
示例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();
}
}
示例8: IsReadAllowed
public bool IsReadAllowed(IPrincipal oPrincipal)
{
foreach (string strRoles in ReadAllowed)
if (oPrincipal.IsInRole(strRoles))
return true;
return false;
}
示例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;
}
示例10: IsWriteDenied
public bool IsWriteDenied(IPrincipal oPrincipal)
{
foreach (string strRoles in WriteDenied)
if (oPrincipal.IsInRole(strRoles))
return true;
return false;
}
示例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;
}
示例12: isInOverideRole
protected virtual bool isInOverideRole(IPrincipal thisUser)
{
if (thisUser == null)
throw new ArgumentNullException("thisUser", "thisUser is null.");
return thisUser.IsInRole("administrator");
}
示例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);
}
示例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));
}
示例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;
}