ProfileEventArgs.Profile 屬性

定義

取得或設定目前要求的使用者設定檔。

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

屬性值

目前要求所使用的使用者設定檔。 預設為 null

範例

下列程式碼範例顯示 Personalize 應用程式在 Global.asax 檔案中宣告的事件。 事件程式碼會根據角色成員資格載入使用者設定檔。

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

備註

您可以在 事件期間 Personalize 使用 Profile 屬性來指定自訂使用者設定檔。 如果事件完成時 PersonalizeProfileEventArgsProfileEventHandler 參數會將其 Profile 屬性設定為不是 null 的值,則 會 ProfileModule 使用 Profile 目前 HttpContext 中的 屬性值。

注意

ProfileModule不會設定 Profile 事件的 屬性 PersonalizeProfileModule只有在事件中的 Personalize 程式碼完成時,才會取得 屬性的值 ProfileProfileEventArgs.Profile如果在事件期間 Personalize 應用程式程式碼未明確設定屬性, Profile 屬性值會是 null

適用於

另請參閱