ProfileModule.Personalize Zdarzenie

Definicja

Występuje przed utworzeniem profilu użytkownika.

public:
 event System::Web::Profile::ProfileEventHandler ^ Personalize;
public event System.Web.Profile.ProfileEventHandler Personalize;
member this.Personalize : System.Web.Profile.ProfileEventHandler 
Public Custom Event Personalize As ProfileEventHandler 

Typ zdarzenia

Przykłady

Poniższy przykład kodu przedstawia Personalize zdarzenie zadeklarowane w pliku Global.asax dla aplikacji. Kod zdarzenia ładuje profil użytkownika dla użytkownika na podstawie członkostwa w rolach.

public void Profile_Personalize(object sender, ProfileEventArgs args)
{
  ProfileCommon userProfile;

  if (User == null) { return; }

  userProfile = (ProfileCommon)ProfileBase.Create(User.Identity.Name);

  if (User.IsInRole("Administrators"))
    userProfile = userProfile.GetProfile("Administrator");
  else
    if (User.IsInRole("Users"))
      userProfile = userProfile.GetProfile("User");
    else
      userProfile = userProfile.GetProfile("Guest");

  if (userProfile != null)
    args.Profile = userProfile;
}
Public Sub Profile_Personalize(sender As Object, args As ProfileEventArgs)
  Dim userProfile As ProfileCommon

  If User Is Nothing Then Return

  userProfile = CType(ProfileBase.Create(User.Identity.Name), ProfileCommon)

  If User.IsInRole("Administrators") Then
    userProfile = userProfile.GetProfile("Administrator")
  Else
    If User.IsInRole("Users") Then
      userProfile = userProfile.GetProfile("User")
    Else
      userProfile = userProfile.GetProfile("Guest")
    End If
  End If

  If Not userProfile Is Nothing Then _
    args.Profile = userProfile
End Sub

Uwagi

Zdarzenie Personalize jest zgłaszane podczas HttpApplication.AcquireRequestState zdarzenia. Możesz uzyskać dostęp do Personalize zdarzenia ProfileModule klasy w pliku Global.asax dla aplikacji ASP.NET przy użyciu Profile_Personalize zdarzenia globalnego, jak pokazano w przykładzie tego tematu.

Możesz użyć Personalize zdarzenia, aby określić niestandardowy profil użytkownika. ProfileEventArgs.Profile Jeśli wartość właściwości określona dla ProfileEventHandler programu obsługi zdarzeń dla Personalize zdarzenia jest ustawiona na wartość, która nie null jest określona po Personalize zakończeniu zdarzenia, ProfileModule zostanie użyta określona wartość właściwości jako wartość ProfileEventArgs.ProfileProfile właściwości bieżącej HttpContext.

Dotyczy