ProfileEventArgs.Profile Właściwość

Definicja

Pobiera lub ustawia profil użytkownika dla bieżącego żądania.

public:
 property System::Web::Profile::ProfileBase ^ Profile { System::Web::Profile::ProfileBase ^ get(); void set(System::Web::Profile::ProfileBase ^ value); };
public System.Web.Profile.ProfileBase Profile { get; set; }
member this.Profile : System.Web.Profile.ProfileBase with get, set
Public Property Profile As ProfileBase

Wartość właściwości

Profil użytkownika do użycia dla bieżącego żądania. Wartość domyślna to null.

Przykłady

Poniższy przykład kodu przedstawia Personalize zdarzenie zadeklarowane w pliku Global.asax dla aplikacji. Kod zdarzenia ładuje profil 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

Właściwość można użyć Profile podczas Personalize zdarzenia, aby określić niestandardowy profil użytkownika. Jeśli po zakończeniu PersonalizeProfileEventArgs zdarzenia parametr ProfileEventHandler właściwości ma ustawioną Profile wartość, która nie nulljest wartością , użyje ProfileModule wartości Profile właściwości w bieżącym HttpContextobiekcie .

Uwaga

Właściwość ProfileModule nie ustawia Profile właściwości dla Personalize zdarzenia. Tylko ProfileModule pobiera wartość Profile właściwości po zakończeniu kodu w zdarzeniu Personalize . ProfileEventArgs.Profile Jeśli właściwość nie jest jawnie ustawiana przez kod aplikacji podczas Personalize zdarzenia, Profile wartość właściwości będzie równa null.

Dotyczy

Zobacz też