Example: Programmatically Accessing the Currently Logged-in User

July 23, 2009
Iron Speed Designer V6.2 and later

This example shows how to retrieve information about currently logged user and his/her roles via a code customization.

Verifying that the currently logged-in user has particular role(s)

This is applicable for all security types, including database security and Active Directory security.

C#:

BaseClasses.Utils.SecurityControls.IsUserInRole(System.Web.HttpContext.Current, "role1;role2;role3");

Visual Basic .NET:

BaseClasses.Utils.SecurityControls.IsUserInRole(System.Web.HttpContext.Current, "role1;role2;role3")

Retrieve the logged-in user’s user ID

C#:

string UserID = SecurityControls.GetCurrentUserID();

Visual basic .NET:

Dim userID As String = SecurityControls.GetCurrentUserID()

Retrieve the current user’s roles

This applies to retrieving Active Directory security roles.

C#:

string usrRoleStr = SecurityControls.GetCurrentUserRoles();

Visual Basic .NET:

Dim usrRoleStr As String = SecurityControls.GetCurrentUserRoles()

Retrieve the logged-in user’s user name

C#:

SecurityControls.GetCurrentUserName();

Visual Basic .NET:

SecurityControls.GetCurrentUserName()

You also can set these values and manually set the logged in user ID without using the Iron Speed Designer security layer.

See Customizing Application Security for details.

See Also

Customizing Application Security

Implementing Custom User Authentication

Example: Overriding Security at the Page Level

Example: Programmatically Accessing the Currently Logged-in User

Example: Access User Name and Password from Sign In Control

Example: Allow Only Active Users to Login

Example: Encrypting Passwords Before Saving to the Database

Example: Restrict Login after Incorrect Password Used