ProfileModule.Personalize Event

Definition

Occurs before the user profile is created.

C#
public event System.Web.Profile.ProfileEventHandler Personalize;

Event Type

Examples

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.

C#
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;
}

Remarks

The Personalize event is raised during the HttpApplication.AcquireRequestState event. 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.

You can use the Personalize event to specify a custom user profile. 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.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1