SelectingProviderEventArgs.User Property

Definition

Gets the authenticated user.

C#
public System.Security.Principal.IPrincipal User { get; }

Property Value

An object that contains the authenticated user.

Examples

The following example shows an event handler for the SelectingProvider event. The event handler uses the SelectingProviderEventArgs object to check the user name and set the role provider to use. The event handler is bound to the SelectingProvider event in the Application_Start method of the Global.asax file.

C#
void Application_Start(object sender, EventArgs e) 
{
    System.Web.ApplicationServices.RoleService.SelectingProvider += 
        new EventHandler<System.Web.ApplicationServices.SelectingProviderEventArgs>(RoleService_SelectingProvider);
}

void RoleService_SelectingProvider
    (object sender, System.Web.ApplicationServices.SelectingProviderEventArgs e)
{
    if (e.User.Identity.Name.IndexOf("@example.com") > 0)
    {
        e.ProviderName = "EmployeeRoleProvider";
    }
    else
    {
        e.ProviderName = "CustomerRoleProvider";
    }
}

Remarks

You use the User property to retrieve information about the user during the SelectingProvider event.

Applies to

Product Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also