RoleService.SelectingProvider 事件

定义

RoleService 实例确定使用哪个角色提供程序检查用户的角色时发生。

public:
 static event EventHandler<System::Web::ApplicationServices::SelectingProviderEventArgs ^> ^ SelectingProvider;
public static event EventHandler<System.Web.ApplicationServices.SelectingProviderEventArgs> SelectingProvider;
member this.SelectingProvider : EventHandler<System.Web.ApplicationServices.SelectingProviderEventArgs> 
Public Shared Custom Event SelectingProvider As EventHandler(Of SelectingProviderEventArgs) 

事件类型

示例

以下示例演示如何将事件处理程序 SelectingProvider 绑定到 Global.asax 文件中的事件。 事件处理程序根据用户名在运行时确定要使用的角色提供程序。

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

注解

RoleService 在确定要使用哪个角色提供程序来检索用户的角色时引发 SelectingProvider 事件。 可以为事件创建事件处理程序, SelectingProvider 以便在运行时选择要使用的角色提供程序。

适用于

另请参阅