O'Reilly logo

Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB by Stefan Schackow, Bilal Haidar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required