共用方式為


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

備註

SelectingProvider類別 RoleService 會在判斷要用來擷取使用者角色的角色提供者時引發 事件。 您可以為事件建立事件處理常式, SelectingProvider 以在執行時間選取要使用的角色提供者。

適用於

另請參閱