User.CurrentPrincipal Eigenschap

Definitie

Hiermee haalt u de huidige principal op (voor beveiliging op basis van rollen).

public:
 property System::Security::Principal::IPrincipal ^ CurrentPrincipal { System::Security::Principal::IPrincipal ^ get(); void set(System::Security::Principal::IPrincipal ^ value); };
public System.Security.Principal.IPrincipal CurrentPrincipal { get; set; }
member this.CurrentPrincipal : System.Security.Principal.IPrincipal with get, set
Public Property CurrentPrincipal As IPrincipal

Waarde van eigenschap

Een IPrincipal waarde die de beveiligingscontext vertegenwoordigt.

Uitzonderingen

De aanroeper heeft niet de vereiste machtiging om de principal in te stellen.

Voorbeelden

In dit voorbeeld wordt gecontroleerd of de toepassing gebruikmaakt van Windows of aangepaste verificatie en deze informatie gebruikt om de eigenschap My.User.Name te parseren.

Function GetUserName() As String
    If TypeOf My.User.CurrentPrincipal Is 
      Security.Principal.WindowsPrincipal Then
        ' The application is using Windows authentication.
        ' The name format is DOMAIN\USERNAME.
        Dim parts() As String = Split(My.User.Name, "\")
        Dim username As String = parts(1)
        Return username
    Else
        ' The application is using custom authentication.
        Return My.User.Name
    End If
End Function

Opmerkingen

U kunt de My.User.CurrentPrincipal eigenschap instellen op een object waarmee de IPrincipal interface wordt geïmplementeerd om aangepaste verificatie in te schakelen.

In de meeste projecttypen wordt met deze eigenschap de huidige principal van de thread opgehaald en ingesteld. In een ASP.NET-toepassing wordt met deze eigenschap de beveiligingsgegevens opgehaald en ingesteld voor de gebruikersidentiteit van de huidige HTTP-aanvraag.

Dit is een geavanceerd lid; Het wordt niet weergegeven in IntelliSense, tenzij u op het tabblad Alles klikt.

Beschikbaarheid per projecttype

Projecttype Available
Windows-toepassing Yes
Klassebibliotheek Yes
Console toepassing Yes
Windows-besturingselementbibliotheek Yes
Webcontrolebibliotheek Yes
Windows-serviceprogramma Yes
Website Yes

Van toepassing op

Zie ook