ProfileEventArgs.Profile 属性

定义

获取或设置当前请求的用户配置文件。Gets or sets the user profile for the current request.

public:
 property System::Web::Profile::ProfileBase ^ Profile { System::Web::Profile::ProfileBase ^ get(); void set(System::Web::Profile::ProfileBase ^ value); };
public System.Web.Profile.ProfileBase Profile { get; set; }
member this.Profile : System.Web.Profile.ProfileBase with get, set
Public Property Profile As ProfileBase

属性值

用于当前请求的用户配置文件。The user profile to use for the current request. 默认值为 nullThe default is null.

示例

下面的代码示例演示了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 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事件期间Profile使用属性来指定自定义用户配置文件。You can use the Profile property during the Personalize event to specify a custom user profile. 如果在Personalize事件完成时null Profile ProfileEventArgs , 的参数ProfileEventHandler将其属性设置为非的值, 则将ProfileModule使用当前中的Profile属性的值HttpContextIf, 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.

备注

ProfileModuleProfile为事件Personalize设置属性。The ProfileModule does not set the Profile property for the Personalize event. ProfileModule Personalize事件中的代码完成时Profile , 仅获取属性的值。The ProfileModule only gets the value of the Profile property when the code in the Personalize event completes. 如果在Personalize事件期间应用程序代码未显式设置Profile null属性, 则属性值将为。 ProfileEventArgs.ProfileIf the ProfileEventArgs.Profile property is not explicitly set by application code during the Personalize event, the Profile property value will be null.

适用于

另请参阅