SelectingProviderEventArgs.User 属性

定义

获取已经过身份验证的用户。

public:
 property System::Security::Principal::IPrincipal ^ User { System::Security::Principal::IPrincipal ^ get(); };
public System.Security.Principal.IPrincipal User { get; }
member this.User : System.Security.Principal.IPrincipal
Public ReadOnly Property User As IPrincipal

属性值

包含已经过身份验证的用户的对象。

示例

以下示例演示事件的事件处理程序 SelectingProvider 。 事件处理程序使用 SelectingProviderEventArgs 对象来检查用户名并设置要使用的角色提供程序。 事件处理程序绑定到 SelectingProvider Global.asax 文件的 方法中的 Application_Start 事件。

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";
    }
}
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    AddHandler System.Web.ApplicationServices.RoleService.SelectingProvider, _
        AddressOf Me.RoleService_SelectingProvider
End Sub

Sub RoleService_SelectingProvider _
(ByVal sender As Object, _
 ByVal e As System.Web.ApplicationServices.SelectingProviderEventArgs)

    If (e.User.Identity.Name.IndexOf("@example.com") > 0) Then
        e.ProviderName = "EmployeeRoleProvider"
    Else
        e.ProviderName = "CustomerRoleProvider"
    End If
End Sub

注解

在事件期间SelectingProviderUser使用 属性检索有关用户的信息。

适用于

另请参阅