User Information Sample

To get samples and instructions for installing them, see the following:

  • Click Samples on the Visual Studio Help menu.

    For more information, see Locating Sample Files.

  • The most recent versions and the complete list of samples are available on the Visual Studio 2008 Samples Web site.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied to a folder under \Program Files\Visual Studio 9\Samples\. For Visual Studio Express Editions, all samples are located on the Internet.

To run this sample

  • Press F5.

Demonstrates

This sample demonstrates these tasks:

  • User name   The current Windows user's name is displayed on the main form. This value is retrieved from the My.User Object.

  • Database access   My.User allows developers to plug in their own means of custom authentication and authorization by means of the IPrincipal and IIdentity interfaces. These interfaces describe aspects of the current user that are independent of a specific authentication and authorization architecture. Implementers of the interfaces define how the user should be authenticated and what roles the user is currently enrolled in. This sample provides a very basic implementation of the IPrincipal and IIdentity interfaces to demonstrate how My.User can be configured to use developer-defined authorization and authentication mechanisms, respectively.

    Security Note:

    The implementation in this sample does not demonstrate secure coding practices. If the user types "password" for the password, the user is authenticated.

  • Authentication mode   The behavior of the program is controlled by the authentication mode. Open the Project Designer by double-clicking the My Project node in Solution Explorer. In the Application tab, Application-defined is selected for the Authentication Mode. When you run the application, the Login form will be displayed.