ProfileEventArgs.Profile Property

Definition

Gets or sets the user profile for the current request.

C#
public System.Web.Profile.ProfileBase Profile { get; set; }

Property Value

The user profile to use for the current request. The default is null.

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 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

You can use the Profile property during the Personalize event to specify a custom user profile. If, when the Personalize event completes, the ProfileEventArgs parameter of the ProfileEventHandler has its Profile property set to a value that's not null, then the ProfileModule uses the value of the Profile property in the current HttpContext.

Note

The ProfileModule does not set the Profile property for the Personalize event. The ProfileModule only gets the value of the Profile property when the code in the Personalize event completes. If the ProfileEventArgs.Profile property is not explicitly set by application code during the Personalize event, the Profile property value will be null.

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

See also