RolePrincipal 构造函数

定义

创建 RolePrincipal 类的新实例。

重载

RolePrincipal(IIdentity)

为指定的 identity 实例化一个 RolePrincipal 对象。

RolePrincipal(SerializationInfo, StreamingContext)

使用指定 RolePrincipal 对象中包含的信息并使用指定的流上下文初始化 SerializationInfo 类的新实例。

RolePrincipal(IIdentity, String)

利用指定的 identity 中的角色信息为指定的 encryptedTicket 实例化 RolePrincipal 对象。

RolePrincipal(String, IIdentity)

使用指定的 identity 为指定的 providerName 实例化 RolePrincipal 对象。

RolePrincipal(String, IIdentity, String)

使用指定的 identity 和指定的 providerName 中的角色信息,为指定的 encryptedTicket 实例化 RolePrincipal 对象。

RolePrincipal(IIdentity)

为指定的 identity 实例化一个 RolePrincipal 对象。

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)

参数

identity
IIdentity

为其创建 RolePrincipal 的用户标识。

例外

identitynull

示例

下面的代码示例创建一个新的 RolePrincipal 对象。 如果 CacheRolesInCookietrue,则示例使用 由 CookieName 属性标识的 Cookie 信息创建 RolePrincipal

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

注解

构造函数的 RolePrincipal 此重载将创建一个新的 RolePrincipal 对象并初始化其属性值。 不会从 由 CookieName 属性标识的 Cookie 中读取缓存的角色信息。 属性 ProviderName 设置为 Name 默认角色提供程序的 。

有关启用角色管理的信息,请参阅 Roles 类。

另请参阅

适用于

RolePrincipal(SerializationInfo, StreamingContext)

使用指定 RolePrincipal 对象中包含的信息并使用指定的流上下文初始化 SerializationInfo 类的新实例。

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)

参数

info
SerializationInfo

要填充数据的 SerializationInfo 对象。

context
StreamingContext

此序列化的目标。

适用于

RolePrincipal(IIdentity, String)

利用指定的 identity 中的角色信息为指定的 encryptedTicket 实例化 RolePrincipal 对象。

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)

参数

identity
IIdentity

为其创建 RolePrincipal 的用户标识。

encryptedTicket
String

包含加密的角色信息的字符串。

例外

identitynull

- 或 -

encryptedTicketnull

示例

下面的代码示例创建一个新的 RolePrincipal 对象。 如果 CacheRolesInCookietrue,则示例使用 由 CookieName 属性标识的 Cookie 信息创建 RolePrincipal

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

注解

重要

将此对象的实例与不受信任的数据一起使用存在安全风险。 仅将此对象与受信任的数据一起使用。 有关详细信息,请参阅 验证所有输入

构造函数的 RolePrincipal 此重载将创建一个新的 RolePrincipal 对象并初始化其属性值。 当前用户的角色信息从提供的 encryptedTicket 中读取,并与 对象一起 RolePrincipal 缓存。 属性 ProviderName 设置为 Name 默认角色提供程序的 。

有关启用角色管理的信息,请参阅 Roles 类。

另请参阅

适用于

RolePrincipal(String, IIdentity)

使用指定的 identity 为指定的 providerName 实例化 RolePrincipal 对象。

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)

参数

providerName
String

用户的角色提供程序的名称。

identity
IIdentity

为其创建 RolePrincipal 的用户标识。

例外

identitynull

providerNamenull

- 或 -

providerName 引用在应用程序的配置中不存在的角色提供程序。

注解

构造函数的 RolePrincipal 此重载将创建一个新的 RolePrincipal 对象并初始化其属性值。 属性 ProviderName 设置为 参数中指定的 providerName 值。

有关启用角色管理的信息,请参阅 Roles 类。

另请参阅

适用于

RolePrincipal(String, IIdentity, String)

使用指定的 identity 和指定的 providerName 中的角色信息,为指定的 encryptedTicket 实例化 RolePrincipal 对象。

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)

参数

providerName
String

用户的角色提供程序的名称。

identity
IIdentity

为其创建 RolePrincipal 的用户标识。

encryptedTicket
String

包含加密的角色信息的字符串。

例外

identitynull

- 或 -

encryptedTicketnull

providerNamenull

- 或 -

providerName 引用在应用程序的配置中不存在的角色提供程序。

注解

重要

将此对象的实例与不受信任的数据一起使用存在安全风险。 仅将此对象与受信任的数据一起使用。 有关详细信息,请参阅 验证所有输入

构造函数的 RolePrincipal 此重载将创建一个新的 RolePrincipal 对象并初始化其属性值。 当前用户的角色信息从提供的 encryptedTicket 中读取,并与 对象一起 RolePrincipal 缓存。 属性 ProviderName 设置为 参数中指定的 providerName 值。

有关启用角色管理的信息,请参阅 Roles 类。

另请参阅

适用于