ProfileMigrateEventHandler 委托
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示将处理 MigrateAnonymous 类事件 ProfileModule 的方法。
public delegate void ProfileMigrateEventHandler(System::Object ^ sender, ProfileMigrateEventArgs ^ e);
public delegate void ProfileMigrateEventHandler(object sender, ProfileMigrateEventArgs e);
type ProfileMigrateEventHandler = delegate of obj * ProfileMigrateEventArgs -> unit
Public Delegate Sub ProfileMigrateEventHandler(sender As Object, e As ProfileMigrateEventArgs)
参数
- sender
- Object
引发ProfileModuleMigrateAnonymous事件的函数。
包含事件数据的 A ProfileMigrateEventArgs 。
示例
下面的代码示例演示一个 Web.config 文件,该文件支持匿名身份验证,以及 MigrateAnonymous ASP.NET 应用程序的 Global.asax 文件中包含的事件。
下面的代码示例演示了一个 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
注解
委托 ProfileMigrateEventHandler 是为 MigrateAnonymous 类的事件 ProfileModule 定义的。 可以在 ASP.NET 应用程序的 Global.asax 文件中访问 MigrateAnonymous > 类的 ProfileModule 事件,如本主题的示例所示。
当使用应用程序登录时,可以使用 MigrateAnonymous 该事件将配置文件属性值从匿名配置文件复制到经过身份验证的配置文件。
启动启用了用户配置文件的应用程序时,ASP.NET 创建一个类型的新 ProfileCommon类,该类继承自 ProfileBase 该类。
ProfileCommon生成类时,将基于 Web.config 文件中指定的配置文件属性添加一个GetProfile方法,使你能够基于用户名检索ProfileCommon对象。 可以使用 GetProfile 当前配置文件的方法检索匿名配置文件的属性值。 然后,可以将匿名属性值复制到经过身份验证的用户的当前配置文件。
扩展方法
| 名称 | 说明 |
|---|---|
| GetMethodInfo(Delegate) |
获取一个对象,该对象表示由指定委托表示的方法。 |