RolePrincipal Konstruktorer

Definition

Skapar en ny instans av RolePrincipal klassen.

Överlagringar

Name Description
RolePrincipal(IIdentity)

Instansierar ett RolePrincipal objekt för den angivna identity.

RolePrincipal(SerializationInfo, StreamingContext)

Initierar en ny instans av klassen med hjälp av RolePrincipal information som finns i det angivna SerializationInfo objektet och med den angivna strömningskontexten.

RolePrincipal(IIdentity, String)

Instansierar ett RolePrincipal objekt för den angivna identity med rollinformation från den angivna encryptedTicket.

RolePrincipal(String, IIdentity)

Instansierar ett RolePrincipal objekt för det angivna identity med hjälp av den angivna providerName.

RolePrincipal(String, IIdentity, String)

Instansierar ett RolePrincipal objekt för den angivna identity med hjälp av den angivna providerName och rollinformationen från den angivna encryptedTicket.

RolePrincipal(IIdentity)

Instansierar ett RolePrincipal objekt för den angivna 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)

Parametrar

identity
IIdentity

Användaridentiteten RolePrincipal som ska skapas för.

Undantag

identity är null.

Exempel

I följande kodexempel skapas ett nytt RolePrincipal objekt. Om CacheRolesInCookie är trueskapar RolePrincipal exemplet med cookieinformation från cookien som identifieras av CookieName egenskapen.

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

Kommentarer

Den här överlagringen RolePrincipal av konstruktorn skapar ett nytt RolePrincipal objekt och initierar dess egenskapsvärden. Cachelagrad rollinformation läse inte från cookien som identifieras av egenskapen CookieName . Egenskapen ProviderName är inställd på Name standardrollprovidern.

Information om hur du aktiverar rollhantering finns i Roles klassen .

Se även

Gäller för

RolePrincipal(SerializationInfo, StreamingContext)

Initierar en ny instans av klassen med hjälp av RolePrincipal information som finns i det angivna SerializationInfo objektet och med den angivna strömningskontexten.

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)

Parametrar

info
SerializationInfo

Objektet SerializationInfo som ska fyllas med data.

context
StreamingContext

Målet för den här serialiseringen.

Gäller för

RolePrincipal(IIdentity, String)

Instansierar ett RolePrincipal objekt för den angivna identity med rollinformation från den angivna 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)

Parametrar

identity
IIdentity

Användaridentiteten RolePrincipal som ska skapas för.

encryptedTicket
String

En sträng som innehåller krypterad rollinformation.

Undantag

identity är null.

-eller-

encryptedTicket är null.

Exempel

I följande kodexempel skapas ett nytt RolePrincipal objekt. Om CacheRolesInCookie är trueskapar RolePrincipal exemplet med cookieinformation från cookien som identifieras av CookieName egenskapen.

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

Kommentarer

Important

Att använda en instans av den här typen med ej betrodda data är en säkerhetsrisk. Använd endast det här objektet med betrodda data. För mer information, se Verifiera alla indata.

Den här överlagringen RolePrincipal av konstruktorn skapar ett nytt RolePrincipal objekt och initierar dess egenskapsvärden. Rollinformation för den aktuella användaren läse från den angivna encryptedTicket och cachelagrade med RolePrincipal -objektet. Egenskapen ProviderName är inställd på Name standardrollprovidern.

Information om hur du aktiverar rollhantering finns i Roles klassen .

Se även

Gäller för

RolePrincipal(String, IIdentity)

Instansierar ett RolePrincipal objekt för det angivna identity med hjälp av den angivna 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)

Parametrar

providerName
String

Namnet på rollprovidern för användaren.

identity
IIdentity

Användaridentiteten RolePrincipal som ska skapas för.

Undantag

identity är null.

providerName är null.

-eller-

providerName refererar till en rollprovider som inte finns i programmets konfiguration.

Kommentarer

Den här överlagringen RolePrincipal av konstruktorn skapar ett nytt RolePrincipal objekt och initierar dess egenskapsvärden. Egenskapen ProviderName är inställd på det värde som anges i parametern providerName .

Information om hur du aktiverar rollhantering finns i Roles klassen .

Se även

Gäller för

RolePrincipal(String, IIdentity, String)

Instansierar ett RolePrincipal objekt för den angivna identity med hjälp av den angivna providerName och rollinformationen från den angivna 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)

Parametrar

providerName
String

Namnet på rollprovidern för användaren.

identity
IIdentity

Användaridentiteten RolePrincipal som ska skapas för.

encryptedTicket
String

En sträng som innehåller krypterad rollinformation.

Undantag

identity är null.

-eller-

encryptedTicket är null.

providerName är null.

-eller-

providerName refererar till en rollprovider som inte finns i programmets konfiguration.

Kommentarer

Important

Att använda en instans av den här typen med ej betrodda data är en säkerhetsrisk. Använd endast det här objektet med betrodda data. För mer information, se Verifiera alla indata.

Den här överlagringen RolePrincipal av konstruktorn skapar ett nytt RolePrincipal objekt och initierar dess egenskapsvärden. Rollinformation för den aktuella användaren läse från den angivna encryptedTicket och cachelagrade med RolePrincipal -objektet. Egenskapen ProviderName är inställd på det värde som anges i parametern providerName .

Information om hur du aktiverar rollhantering finns i Roles klassen .

Se även

Gäller för