Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

WebUser Class

Note: This class is new in the .NET Framework version 2.0.

Provides access to the information about the current user.

Namespace: Microsoft.VisualBasic.ApplicationServices
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

public class WebUser : User
public class WebUser extends User
public class WebUser extends User

For more detailed information, see the Visual Basic topic My.User Object.

The properties and methods exposed by the My.User object provide access to the information about the current user. The meaning of "current user" differs slightly between Windows and Web applications. In a Windows application, the current user is the user who runs the application. In a Web application, the current user is the user who accesses the application.

The My.User property also provides access to the IPrincipal for the current user. A principal object represents the user's security context, including that user's identity and any roles to which the user belongs.

For Windows applications, this property provides the same functionality as the CurrentPrincipal property. For Web applications, this property provides the same functionality as the User property of the object returned by the Current property.

NoteNote

For Windows applications, only projects built on the Windows Application template initialize the My.User object by default. In all other Windows project types, you must initialize the My.User object by calling the My.User.InitializeWithWindowsUser Method explicitly or by assigning a value to CurrentPrincipal.

NoteNote

The My.User object cannot report information about the current Windows user when run under Windows 95 and Windows 98 because those operating systems do not support the concept of a logged-on user. You must implement custom authentication to use the My.User object on those operating systems. For more information, see Walkthrough: Implementing Custom Authentication and Authorization.

The following table lists examples of tasks involving the My.User object.

To

See

Get the user's login name

How to: Determine a User's Login Name

Get the user's domain name, if the application uses Windows authentication

How to: Determine the User's Domain

Determine the user's role

How to: Determine if a User is in a Group

Implement custom authentication

Walkthrough: Implementing Custom Authentication and Authorization

This example checks if the application is using Windows or custom authentication, and uses that information to parse the My.User.Name property.

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

System.Object
   Microsoft.VisualBasic.ApplicationServices.User
    Microsoft.VisualBasic.ApplicationServices.WebUser
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.