WindowsAuthenticationEventArgs.User Egenskap

Definition

Hämtar eller ställer in objektet IPrincipal som ska associeras med den aktuella begäran.

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

Egenskapsvärde

Objektet IPrincipal som ska associeras med den aktuella begäran.

Exempel

I följande kodexempel används händelsen WindowsAuthentication_OnAuthenticate för att ange User egenskapen för den aktuella HttpContext till ett anpassat IPrincipal objekt.

public void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs args)
{
  if (!args.Identity.IsAnonymous)
  {
    args.User = new Samples.AspNet.Security.MyPrincipal(args.Identity);
  }
}
Public Sub WindowsAuthentication_OnAuthenticate(sender As Object, args As WindowsAuthenticationEventArgs)
  If Not args.Identity.IsAnonymous Then
    args.User = New Samples.AspNet.Security.MyPrincipal(args.Identity)
  End If
End Sub

Kommentarer

Du kan använda User egenskapen för att ange User egenskapen för den aktuella HttpContext till ett anpassat IPrincipal objekt.

Om du inte anger något värde för egenskapen User under händelsen WindowsAuthentication_OnAuthenticate används den Windows identitet som tillhandahålls av IIS som identitet för den aktuella begäran. Om IIS använder anonym autentisering Identity anges egenskapen till den identitet som returneras av GetAnonymous metoden.

Gäller för

Se även