ProfileModule 类

定义

管理用户配置文件和配置文件事件的创建。Manages the creation of the user profile and profile events. 此类不能被继承。This class cannot be inherited.

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 文件, 该文件启用支持匿名用户的匿名标识和配置文件属性。The following example shows a Web.config file that enables anonymous identification and profile properties that support anonymous users.

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

下面的代码示例演示 ASP.NET MigrateAnonymous应用程序的 global.asax 文件中包含的事件。The following code example shows the MigrateAnonymous event included in the Global.asax file for an ASP.NET application. MigrateAnonymous事件将配置文件属性值从匿名配置文件复制到当前用户的配置文件。The MigrateAnonymous event copies profile property values from the anonymous profile to the profile for the current user.

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创建用户配置文件, 并将其存储Profile在当前HttpContext的属性中。When the user profile is enabled, ASP.NET uses the ProfileModule to create the user profile and store it in the Profile property of the current HttpContext.

ProfileModule公开以下事件, 你可以处理这些事件, 以在应用程序中配置身份验证:The ProfileModule exposes the following events you can handle to configure authentication in your application:

  • MigrateAnonymous事件, 用于在匿名用户登录时将配置文件设置从匿名配置文件迁移到经过身份验证的配置文件。The MigrateAnonymous event, to migrate profile settings from an anonymous profile to an authenticated profile when an anonymous user logs in.

  • Personalize事件, 用于自定义用户配置文件的创建方式。The Personalize event, to customize how the user profile is created.

  • 事件, 用于控制在AutomaticSaveEnabled属性设置为true时如何保存用户配置文件。 ProfileAutoSavingThe ProfileAutoSaving event, to control how the user profile is saved when the AutomaticSaveEnabled property is set to true.

有关启用用户配置文件的信息, 请参阅Profile 元素 (ASP.NET Settings Schema)For information about enabling the user profile, see profile Element (ASP.NET Settings Schema).

构造函数

ProfileModule()

初始化 ProfileModule 类的新实例。Initializes a new instance of the ProfileModule class.

方法

Dispose()

释放由 ProfileModule 使用的所有资源。Releases all resources used by the ProfileModule.

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)
Init(HttpApplication)

在创建 ProfileModule 对象时调用初始化代码。Calls initialization code when a ProfileModule object is created.

MemberwiseClone()

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

(继承自 Object)
ToString()

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

(继承自 Object)

事件

MigrateAnonymous

当配置文件的匿名用户登录时发生。Occurs when the anonymous user for a profile logs in.

Personalize

在创建用户配置文件之前发生。Occurs before the user profile is created.

ProfileAutoSaving

在启用自动配置文件保存的情况下在页面执行结束时发生。Occurs at the end of page execution if automatic profile saving is enabled.

适用于

另请参阅