RolePrincipal Constructors

Definition

Creates a new instance of the RolePrincipal class.

Overloads

RolePrincipal(IIdentity)

Instantiates a RolePrincipal object for the specified identity.

RolePrincipal(SerializationInfo, StreamingContext)

Initializes a new instance of the RolePrincipal class using information that is contained in the specified SerializationInfo object and using the specified streaming context.

RolePrincipal(IIdentity, String)

Instantiates a RolePrincipal object for the specified identity with role information from the specified encryptedTicket.

RolePrincipal(String, IIdentity)

Instantiates a RolePrincipal object for the specified identity using the specified providerName.

RolePrincipal(String, IIdentity, String)

Instantiates a RolePrincipal object for the specified identity using the specified providerName and role information from the specified encryptedTicket.

RolePrincipal(IIdentity)

Instantiates a RolePrincipal object for the specified identity.

public:
 RolePrincipal(System::Security::Principal::IIdentity ^ identity);
public RolePrincipal (System.Security.Principal.IIdentity identity);
new System.Web.Security.RolePrincipal : System.Security.Principal.IIdentity -> System.Web.Security.RolePrincipal
Public Sub New (identity As IIdentity)

Parameters

identity
IIdentity

The user identity to create the RolePrincipal for.

Exceptions

identity is null.

Examples

The following code example creates a new RolePrincipal object. If CacheRolesInCookie is true, the example creates the RolePrincipal with cookie information from the cookie identified by the CookieName property.

RolePrincipal r;

if (Roles.CacheRolesInCookie)
{
  string roleCookie = "";

  HttpCookie cookie = HttpContext.Current.Request.Cookies[Roles.CookieName];
  if (cookie != null) { roleCookie = cookie.Value; }

  r = new RolePrincipal(User.Identity, roleCookie);
}
else
{
  r = new RolePrincipal(User.Identity);
}
Dim r As RolePrincipal

If Roles.CacheRolesInCookie Then
  Dim roleCookie As String = ""

  Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies(Roles.CookieName)
  If Not cookie Is Nothing Then roleCookie = cookie.Value

  r = New RolePrincipal(User.Identity, roleCookie)
Else
  r = new RolePrincipal(User.Identity)
End If

Remarks

This overload of the RolePrincipal constructor creates a new RolePrincipal object and initializes its property values. Cached role information is not read from the cookie identified by the CookieName property. The ProviderName property is set to the Name of the default role provider.

For information on enabling role management, see the Roles class.

See also

Applies to

RolePrincipal(SerializationInfo, StreamingContext)

Initializes a new instance of the RolePrincipal class using information that is contained in the specified SerializationInfo object and using the specified streaming context.

protected:
 RolePrincipal(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected RolePrincipal (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Web.Security.RolePrincipal : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Web.Security.RolePrincipal
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parameters

info
SerializationInfo

The SerializationInfo object to populate with data.

context
StreamingContext

The destination for this serialization.

Applies to

RolePrincipal(IIdentity, String)

Instantiates a RolePrincipal object for the specified identity with role information from the specified encryptedTicket.

public:
 RolePrincipal(System::Security::Principal::IIdentity ^ identity, System::String ^ encryptedTicket);
public RolePrincipal (System.Security.Principal.IIdentity identity, string encryptedTicket);
new System.Web.Security.RolePrincipal : System.Security.Principal.IIdentity * string -> System.Web.Security.RolePrincipal
Public Sub New (identity As IIdentity, encryptedTicket As String)

Parameters

identity
IIdentity

The user identity to create the RolePrincipal for.

encryptedTicket
String

A string that contains encrypted role information.

Exceptions

identity is null.

-or-

encryptedTicket is null.

Examples

The following code example creates a new RolePrincipal object. If CacheRolesInCookie is true, the example creates the RolePrincipal with cookie information from the cookie identified by the CookieName property.

RolePrincipal r;

if (Roles.CacheRolesInCookie)
{
  string roleCookie = "";

  HttpCookie cookie = HttpContext.Current.Request.Cookies[Roles.CookieName];
  if (cookie != null) { roleCookie = cookie.Value; }

  r = new RolePrincipal(User.Identity, roleCookie);
}
else
{
  r = new RolePrincipal(User.Identity);
}
Dim r As RolePrincipal

If Roles.CacheRolesInCookie Then
  Dim roleCookie As String = ""

  Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies(Roles.CookieName)
  If Not cookie Is Nothing Then roleCookie = cookie.Value

  r = New RolePrincipal(User.Identity, roleCookie)
Else
  r = new RolePrincipal(User.Identity)
End If

Remarks

Important

Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Validate All Inputs.

This overload of the RolePrincipal constructor creates a new RolePrincipal object and initializes its property values. Role information for the current user is read from the supplied encryptedTicket and cached with the RolePrincipal object. The ProviderName property is set to the Name of the default role provider.

For information on enabling role management, see the Roles class.

See also

Applies to

RolePrincipal(String, IIdentity)

Instantiates a RolePrincipal object for the specified identity using the specified providerName.

public:
 RolePrincipal(System::String ^ providerName, System::Security::Principal::IIdentity ^ identity);
public RolePrincipal (string providerName, System.Security.Principal.IIdentity identity);
new System.Web.Security.RolePrincipal : string * System.Security.Principal.IIdentity -> System.Web.Security.RolePrincipal
Public Sub New (providerName As String, identity As IIdentity)

Parameters

providerName
String

The name of the role provider for the user.

identity
IIdentity

The user identity to create the RolePrincipal for.

Exceptions

identity is null.

providerName is null.

-or-

providerName refers to a role provider that does not exist in the configuration for the application.

Remarks

This overload of the RolePrincipal constructor creates a new RolePrincipal object and initializes its property values. The ProviderName property is set to the value specified in the providerName parameter.

For information on enabling role management, see the Roles class.

See also

Applies to

RolePrincipal(String, IIdentity, String)

Instantiates a RolePrincipal object for the specified identity using the specified providerName and role information from the specified encryptedTicket.

public:
 RolePrincipal(System::String ^ providerName, System::Security::Principal::IIdentity ^ identity, System::String ^ encryptedTicket);
public RolePrincipal (string providerName, System.Security.Principal.IIdentity identity, string encryptedTicket);
new System.Web.Security.RolePrincipal : string * System.Security.Principal.IIdentity * string -> System.Web.Security.RolePrincipal
Public Sub New (providerName As String, identity As IIdentity, encryptedTicket As String)

Parameters

providerName
String

The name of the role provider for the user.

identity
IIdentity

The user identity to create the RolePrincipal for.

encryptedTicket
String

A string that contains encrypted role information.

Exceptions

identity is null.

-or-

encryptedTicket is null.

providerName is null.

-or-

providerName refers to a role provider that does not exist in the configuration for the application.

Remarks

Important

Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Validate All Inputs.

This overload of the RolePrincipal constructor creates a new RolePrincipal object and initializes its property values. Role information for the current user is read from the supplied encryptedTicket and cached with the RolePrincipal object. The ProviderName property is set to the value specified in the providerName parameter.

For information on enabling role management, see the Roles class.

See also

Applies to