ProfileModule.Personalize 事件

定义

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

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 

示例

下面的代码示例演示了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");
  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 事件HttpApplication.AcquireRequestState在事件期间引发。The 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. Personalize Personalize null ProfileModule如果为事件的ProfileEventHandler事件处理程序指定的属性值设置为在事件结束时不为的值,则将使用指定的值ProfileEventArgs.Profile ProfileEventArgs.Profile属性作为Profile 当前HttpContext的属性的值。If 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.

适用于