Public NotInheritable Class ProfileModule Implements IHttpModule
Dim instance As ProfileModule
public sealed class ProfileModule : IHttpModule
public ref class ProfileModule sealed : IHttpModule
public final class ProfileModule implements IHttpModule
当启用用户配置文件时,ASP.NET 使用 ProfileModule 来创建用户配置文件,并将其存储在当前 HttpContext 的 Profile 属性中。
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 事件将配置文件属性值从匿名配置文件复制到当前用户的配置文件。
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
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(); }
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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。