語言

RolePrincipal 建構函式

定義

建立一個新的類別實例 RolePrincipal 。

多載

名稱 Description
RolePrincipal(IIdentity)

為指定的RolePrincipal物件實identity例化一個物件。

RolePrincipal(SerializationInfo, StreamingContext)

利用指定RolePrincipal物件中包含的資訊及指定的串流上下文初始化該類別的新SerializationInfo實例。

RolePrincipal(IIdentity, String)

實 RolePrincipal 例化指定 identity 物件,並使用指定 encryptedTicket角色資訊。

RolePrincipal(String, IIdentity)

使用指定的RolePrincipal物件實例identityproviderName化 。

RolePrincipal(String, IIdentity, String)

利用指定 RolePrincipal 與 角色資訊identity實providerName例化指定的物件encryptedTicket。

RolePrincipal(IIdentity)

為指定的RolePrincipal物件實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)

參數

identity
IIdentity

使用者身份來建立 RolePrincipal for。

例外狀況

identity 是 null。

範例

以下程式碼範例會建立一個新的 RolePrincipal 物件。 若CacheRolesInCookie為 true,範例則由屬性識別RolePrincipal的 cookie 建立 CookieName 與 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)

實 RolePrincipal 例化指定 identity 物件,並使用指定 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)

參數

identity
IIdentity

使用者身份來建立 RolePrincipal for。

encryptedTicket
String

一個包含加密角色資訊的字串。

例外狀況

identity 是 null。

-或-

encryptedTicket 是 null。

範例

以下程式碼範例會建立一個新的 RolePrincipal 物件。 若CacheRolesInCookie為 true,範例則由屬性識別RolePrincipal的 cookie 建立 CookieName 與 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

備註

Important

使用這種類型的實例與不受信任的資料存在安全風險。 此物件僅用於受信任的資料。 如需詳細資訊,請參閱 驗證所有輸入。

建構子的過載 RolePrincipal 會產生一個新 RolePrincipal 物件並初始化其屬性值。 目前使用者的角色資訊會從所提供的encryptedTicket物件讀取並快取。RolePrincipal 屬性ProviderName設定為預設角色提供者的 。Name

關於角色管理的相關資訊,請參閱該課程。Roles

另請參閱

適用於

RolePrincipal(String, IIdentity)

使用指定的RolePrincipal物件實例identityproviderName化 。

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 for。

例外狀況

identity 是 null。

providerName 是 null。

-或-

providerName 指的是應用程式設定中不存在的角色提供者。

備註

建構子的過載 RolePrincipal 會產生一個新 RolePrincipal 物件並初始化其屬性值。 屬性 ProviderName 設定為參數中 providerName 指定的值。

關於角色管理的相關資訊,請參閱該課程。Roles

另請參閱

適用於

RolePrincipal(String, IIdentity, String)

利用指定 RolePrincipal 與 角色資訊identity實providerName例化指定的物件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)

參數

providerName
String

使用者的角色提供者名稱。

identity
IIdentity

使用者身份來建立 RolePrincipal for。

encryptedTicket
String

一個包含加密角色資訊的字串。

例外狀況

identity 是 null。

-或-

encryptedTicket 是 null。

providerName 是 null。

-或-

providerName 指的是應用程式設定中不存在的角色提供者。

備註

Important

使用這種類型的實例與不受信任的資料存在安全風險。 此物件僅用於受信任的資料。 如需詳細資訊,請參閱 驗證所有輸入。

建構子的過載 RolePrincipal 會產生一個新 RolePrincipal 物件並初始化其屬性值。 目前使用者的角色資訊會從所提供的encryptedTicket物件讀取並快取。RolePrincipal 屬性 ProviderName 設定為參數中 providerName 指定的值。

關於角色管理的相關資訊,請參閱該課程。Roles

另請參閱

適用於