Редагувати

Поділитися через


WebUser Class

Definition

Provides access to the information about the current user.

public ref class WebUser : Microsoft::VisualBasic::ApplicationServices::User
public class WebUser : Microsoft.VisualBasic.ApplicationServices.User
type WebUser = class
    inherit User
Public Class WebUser
Inherits User
Inheritance
WebUser

Examples

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

Remarks

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.

Note

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 InitializeWithWindowsUser method explicitly or by assigning a value to CurrentPrincipal.

Constructors

WebUser()

Initializes a new instance of the WebUser class.

Properties

CurrentPrincipal

Gets or sets the current principal (for role-based security).

(Inherited from User)
InternalPrincipal

Gets or sets the principal object representing the current user.

IsAuthenticated

Gets a value that indicates whether the user has been authenticated.

(Inherited from User)
Name

Gets the name of the current user.

(Inherited from User)

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeWithWindowsUser()

Sets the thread's current principal to the Windows user that started the application.

(Inherited from User)
IsInRole(BuiltInRole)

Determines whether the current user belongs to the specified role.

(Inherited from User)
IsInRole(String)

Determines whether the current user belongs to the specified role.

(Inherited from User)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also