This documentation is archived and is not being maintained.

ProfileEventArgs.Profile Property

Gets or sets the user profile for the current request.

Namespace: System.Web.Profile
Assembly: System.Web (in system.web.dll)

public ProfileBase Profile { get; set; }
/** @property */
public ProfileBase get_Profile ()

/** @property */
public void set_Profile (ProfileBase value)

public function get Profile () : ProfileBase

public function set Profile (value : ProfileBase)

Not applicable.

Property Value

The user profile to use for the current request. The default is a null reference (Nothing in Visual Basic).

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 a null reference (Nothing in Visual Basic), then the ProfileModule uses the value of the Profile property in the current HttpContext.

NoteNote:

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 a null reference (Nothing in Visual Basic).

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.

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Show: