RolePrincipal 建構函式

定義

建立 RolePrincipal 類別的新執行個體。

多載

RolePrincipal(IIdentity)

產生指定之 identityRolePrincipal 物件。

RolePrincipal(SerializationInfo, StreamingContext)

使用指定之 RolePrincipal 物件中包含的資訊,以及使用指定的資料流內容,初始化 SerializationInfo 類別的新執行個體。

RolePrincipal(IIdentity, String)

使用指定 identity 中的角色資訊,產生指定之 encryptedTicketRolePrincipal 物件。

RolePrincipal(String, IIdentity)

使用指定的 identity,產生指定之 providerNameRolePrincipal 物件。

RolePrincipal(String, IIdentity, String)

使用指定的 identity,以及來自指定 providerName 的角色資訊,產生指定之 encryptedTicketRolePrincipal 物件。

RolePrincipal(IIdentity)

產生指定之 identityRolePrincipal 物件。

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 ,則此範例會 RolePrincipal 從 屬性所識別的 CookieName Cookie 中建立具有 Cookie 資訊的 。

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 中的角色資訊,產生指定之 encryptedTicketRolePrincipal 物件。

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 ,則此範例會 RolePrincipal 從 屬性所識別的 CookieName Cookie 中建立具有 Cookie 資訊的 。

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,產生指定之 providerNameRolePrincipal 物件。

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 的角色資訊,產生指定之 encryptedTicketRolePrincipal 物件。

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 類別。

另請參閱

適用於