LocationMy.User.CurrentPrincipal SyntaxDim result As System.Security.Principal.IPrincipal = _ My.User.CurrentPrincipal DescriptionThe 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
ExampleThe 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
See AlsoInitializeWithWindowsUser Method, IsAuthenticated Property, IsInRole Method, Name Property (My.User), User Object |