ProfileEventArgs 类

定义

Personalize 类的 ProfileModule 事件提供数据。Provides data for the Personalize event of the ProfileModule class.

public ref class ProfileEventArgs sealed : EventArgs
public sealed class ProfileEventArgs : EventArgs
type ProfileEventArgs = class
    inherit EventArgs
Public NotInheritable Class ProfileEventArgs
Inherits EventArgs
继承
ProfileEventArgs

示例

下面的代码示例演示了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事件期间ProfileEventArgs使用类来指定自定义用户配置文件。You can use the ProfileEventArgs class 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.

构造函数

ProfileEventArgs(HttpContext)

创建 ProfileEventArgs 类的实例。Creates an instance of the ProfileEventArgs class.

属性

Context

获取当前请求的 HttpContextGets the HttpContext for the current request.

Profile

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

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅