14.2. The RolePrincipal Class

Because the Role Manager feature's main purpose is to supply an IPrincipal based object, it includes an implementation of this interface with the RolePrincipal class. The RolePrincipal is intended for use anywhere a Framework application (ASP.NET or non-ASP.NET) expects to find an IPrincipal for IsInRole calls. RolePrincipal also exposes some additional methods for retrieving all of a user's roles as well as for handling some of the work necessary when using cookie caching.

C#

public sealed class RolePrincipal : IPrincipal, ISerializable
{
  //Constructors
  public RolePrincipal(IIdentity identity, string encryptedTicket)
  public RolePrincipal(IIdentity identity)
  public RolePrincipal(string providerName, IIdentity identity)
  public RolePrincipal(string providerName, IIdentity identity,
                       string encryptedTicket)

  //Cookie caching related methods
  public string ToEncryptedTicket()

  //Role Manager and IPrincipal related functionality
  public string[] GetRoles()
  public bool IsInRole(string role)
  public void SetDirty()

  //Public properties not related to cookie caching
  public int Version { get; }
  public IIdentity Identity { get; }
  public string ProviderName { get }
  public bool IsRoleListCached { get; }

  //Public properties related to cookie caching
  public DateTime ExpireDate { get; }
  public DateTime IssueDate { get; }
  public bool Expired {get; }
  public String CookiePath { get; }
  public bool CachedListChanged { get; }
}

VB.NET

<Serializable(), AspNetHostingPermission( ...

Get Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.