.NET Framework 类库
ProfileModule 类

注意:此类在 .NET Framework 2.0 版中是新增的。

管理用户配置文件和配置文件事件的创建。无法继承此类。

命名空间:System.Web.Profile
程序集:System.Web(在 system.web.dll 中)

语法

Visual Basic(声明)
Public NotInheritable Class ProfileModule
    Implements IHttpModule
Visual Basic(用法)
Dim instance As ProfileModule
C#
public sealed class ProfileModule : IHttpModule
C++
public ref class ProfileModule sealed : IHttpModule
J#
public final class ProfileModule implements IHttpModule
JScript
public final class ProfileModule implements IHttpModule
备注

当启用用户配置文件时,ASP.NET 使用 ProfileModule 来创建用户配置文件,并将其存储在当前 HttpContextProfile 属性中。

ProfileModule 公开下面的事件,您可以处理这些事件以在应用程序中配置身份验证:

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

  • Personalize 事件,用于自定义如何创建用户配置文件。

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

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

示例

下面的示例演示一个 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>

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

Visual Basic
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()
End Sub
C#
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(); 
}
.NET Framework 安全性

继承层次结构

System.Object
  System.Web.Profile.ProfileModule
线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0
请参见

标记 :


Page view tracker