ProfileModule.Personalize 事件


在创建用户配置文件之前发生。Occurs before the user profile is created.

 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 




下面的代码示例演示了 Personalize 在应用程序的 global.asax 文件中声明的事件。The following code example shows the Personalize event declared in the Global.asax file for an application. 事件代码基于角色成员身份加载用户的用户配置文件。The event code loads a user profile for a user based on role membership.

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");
    if (User.IsInRole("Users"))
      userProfile = userProfile.GetProfile("User");
      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")
    If User.IsInRole("Users") Then
      userProfile = userProfile.GetProfile("User")
      userProfile = userProfile.GetProfile("Guest")
    End If
  End If

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


事件 Personalize 在事件期间引发 HttpApplication.AcquireRequestStateThe Personalize event is raised during the HttpApplication.AcquireRequestState event. 你可以 Personalize ProfileModule 使用全局事件访问 ASP.NET 应用程序的 global.asax 文件中的类的事件, Profile_Personalize 如本主题的示例中所示。You can access the Personalize event of the ProfileModule class in the Global.asax file for your ASP.NET application using the Profile_Personalize global event as shown in the example for this topic.

可以使用 Personalize 事件指定自定义用户配置文件。You can use the Personalize event to specify a custom user profile. 如果为 ProfileEventArgs.Profile ProfileEventHandler 事件的事件处理程序指定的属性值 Personalize 设置为在事件结束时不为的值 null ,则 Personalize ProfileModule 将使用属性的指定值 ProfileEventArgs.Profile 作为当前的属性的值 Profile HttpContextIf the ProfileEventArgs.Profile property value specified for the ProfileEventHandler event handler for the Personalize event is set to a value that is not null when the Personalize event ends, then the ProfileModule will use the specified value of the ProfileEventArgs.Profile property as the value of the Profile property of the current HttpContext.