ProfileModule 类

定义

管理用户配置文件和配置文件事件的创建。 此类不能被继承。

public ref class ProfileModule sealed : System::Web::IHttpModule
public sealed class ProfileModule : System.Web.IHttpModule
type ProfileModule = class
    interface IHttpModule
Public NotInheritable Class ProfileModule
Implements IHttpModule
继承
ProfileModule
实现

示例

以下示例演示一个Web.config文件,该文件启用匿名标识和支持匿名用户的配置文件属性。

<configuration>  
  <system.web>  
    <authentication mode="Forms" >  
      <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" />  
    </authentication>  

    <anonymousIdentification enabled="true" />  

    <profile enabled="true" defaultProvider="AspNetSqlProvider">  
      <properties>  
        <add name="ZipCode" allowAnonymous="true" />  
        <add name="CityAndState" allowAnonymous="true" />  
        <add name="StockSymbols" type="System.Collections.ArrayList" allowAnonymous="true" />  
      </properties>  
    </profile>  
  </system.web>  
</configuration>  

下面的代码示例演示 MigrateAnonymous ASP.NET 应用程序的 Global.asax 文件中包含的 事件。 事件 MigrateAnonymous 将匿名配置文件中的配置文件属性值复制到当前用户的配置文件。

public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
{
  ProfileCommon anonymousProfile = Profile.GetProfile(args.AnonymousID);

  Profile.ZipCode = anonymousProfile.ZipCode;
  Profile.CityAndState = anonymousProfile.CityAndState;
  Profile.StockSymbols = anonymousProfile.StockSymbols;

  ////////
  // Delete the anonymous profile. If the anonymous ID is not 
  // needed in the rest of the site, remove the anonymous cookie.

  ProfileManager.DeleteProfile(args.AnonymousID);
  AnonymousIdentificationModule.ClearAnonymousIdentifier(); 

  // Delete the user row that was created for the anonymous user.
  Membership.DeleteUser(args.AnonymousID, true);

}
Public Sub Profile_OnMigrateAnonymous(sender As Object, args As ProfileMigrateEventArgs)
  Dim anonymousProfile As ProfileCommon = Profile.GetProfile(args.AnonymousID)

  Profile.ZipCode = anonymousProfile.ZipCode
  Profile.CityAndState = anonymousProfile.CityAndState
  Profile.StockSymbols = anonymousProfile.StockSymbols

  ''''''''
  ' Delete the anonymous profile. If the anonymous ID is not 
  ' needed in the rest of the site, remove the anonymous cookie.

  ProfileManager.DeleteProfile(args.AnonymousID)
  AnonymousIdentificationModule.ClearAnonymousIdentifier()

  ' Delete the user row that was created for the anonymous user.
  Membership.DeleteUser(args.AnonymousID, True)
End Sub

注解

启用用户配置文件后,ASP.NET 使用 ProfileModule 创建用户配置文件并将其存储在当前 HttpContext的 属性中Profile

公开 ProfileModule 了可在应用程序中配置身份验证的以下事件:

  • 事件,用于 MigrateAnonymous 在匿名用户登录时将配置文件设置从匿名配置文件迁移到经过身份验证的配置文件。

  • 事件 Personalize ,用于自定义用户配置文件的创建方式。

  • 事件ProfileAutoSaving,用于控制在 属性设置为 trueAutomaticSaveEnabled如何保存用户配置文件。

有关启用用户配置文件的信息,请参阅 配置文件元素 (ASP.NET 设置架构)

构造函数

ProfileModule()

初始化 ProfileModule 类的新实例。

方法

Dispose()

释放由 ProfileModule 使用的所有资源。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
Init(HttpApplication)

在创建 ProfileModule 对象时调用初始化代码。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

事件

MigrateAnonymous

当配置文件的匿名用户登录时发生。

Personalize

在创建用户配置文件之前发生。

ProfileAutoSaving

在启用自动配置文件保存的情况下在页面执行结束时发生。

适用于

另请参阅