CurrentPrincipal Property


CurrentPrincipal Property

Location

My.User.CurrentPrincipal

Syntax

     Dim result As System.Security.Principal.IPrincipal = _        My.User.CurrentPrincipal 

Description

The CurrentPrincipal property gets or sets the current role-based security principal (the security context, with access to user and role information) using the System.Security.Principal.IPrincipal interface. In most Windows applications, this interface will exist through an instance of Security.Principal.WindowsPrincipal. However, other custom principal formats are possible.

Usage at a Glance

  • An exception is thrown if you attempt to update this property without sufficient permissions.

  • In ASP.NET applications, the security information refers to the user associated with the current HTTP request.

Example

The following example obtains the user name. This example checks if the application is using Windows or custom authentication and uses that information to parse the My.User.Name property.

     Public Function GetCurrentUserName(  ) As String        If TypeOf My.User.CurrentPrincipal Is _              System.Security.Principal.WindowsPrincipal Then           ' ----- Windows username = "domain\user".           Return Mid(My.User.Name, Instr(My.User.Name, "\") + 1)        Else           ' ----- Some other custom type of user.           Return My.User.Name        End If     End Function 

Related Framework Entries

  • Microsoft.VisualBasic.ApplicationServices.User.CurrentPrincipal Property

  • Microsoft.VisualBasic.ApplicationServices.WebUser.CurrentPrincipal Property

  • System.Security.Principal.GenericPrincipal

  • System.Security.Principal.IPrincipal Interface

  • System.Security.Principal.WindowsPrincipal

See Also

InitializeWithWindowsUser Method, IsAuthenticated Property, IsInRole Method, Name Property (My.User), User Object




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net