ProfileEventHandler 委托

定义

表示将用来处理 PersonalizeProfileModule 事件的方法。Represents the method that will handle the Personalize event of a ProfileModule.

public delegate void ProfileEventHandler(System::Object ^ sender, ProfileEventArgs ^ e);
public delegate void ProfileEventHandler(object sender, ProfileEventArgs e);
type ProfileEventHandler = delegate of obj * ProfileEventArgs -> unit
Public Delegate Sub ProfileEventHandler(sender As Object, e As ProfileEventArgs)

参数

sender
Object

引发 ProfileModule 事件的 PersonalizeThe ProfileModule that raised the Personalize event.

e
ProfileEventArgs

包含事件数据的 ProfileEventArgsA ProfileEventArgs that contains the event data.

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

注解

委托是ProfileModule Personalize为类的事件定义的。 ProfileEventHandlerThe ProfileEventHandler delegate is defined for the Personalize event of the ProfileModule class. 你可以使用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. ProfileEventArgs Personalize ProfileModule Profile如果在事件Personalize完成时为事件的ProfileEventHandler指定参数的属性设置为非null值,则将使用该值作为Profile当前HttpContext的属性。If the Profile property of the ProfileEventArgs parameter specified for the Personalize event's ProfileEventHandler is set to a non-null value when the Personalize event completes, then the ProfileModule will use that value for the Profile property of the current HttpContext.

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

适用于

另请参阅