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 属性来指定自定义用户配置文件。 如果 事件完成时, 的 参数的 Profile 属性设置为非 null的值,则 ProfileModule 使用当前 HttpContext中的 属性的值ProfileProfileEventHandlerProfileEventArgsPersonalize

备注

ProfileModule不设置 Profile 事件的 属性PersonalizeProfileModule仅在事件中的Personalize代码完成时获取 属性的值ProfileProfileEventArgs.Profile如果事件期间Personalize应用程序代码未显式设置属性,则Profile属性值将为 null

适用于

另请参阅