ProfileModule.ProfileAutoSaving 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
如果启用了自动配置文件保存,则发生在页面执行结束时。
public:
event System::Web::Profile::ProfileAutoSaveEventHandler ^ ProfileAutoSaving;
public event System.Web.Profile.ProfileAutoSaveEventHandler ProfileAutoSaving;
member this.ProfileAutoSaving : System.Web.Profile.ProfileAutoSaveEventHandler
Public Custom Event ProfileAutoSaving As ProfileAutoSaveEventHandler
事件类型
示例
下面的代码示例演示 ProfileAutoSaving ASP.NET 应用程序的 Global.asax 文件中包含的事件。
public void Profile_ProfileAutoSaving(object sender, ProfileAutoSaveEventArgs args)
{
if (Profile.Cart.HasChanged)
args.ContinueWithProfileAutoSave = true;
else
args.ContinueWithProfileAutoSave = false;
}
Public Sub Profile_ProfileAutoSaving(sender As Object, args As ProfileAutoSaveEventArgs)
If Profile.Cart.HasChanged Then
args.ContinueWithProfileAutoSave = True
Else
args.ContinueWithProfileAutoSave = False
End If
End Sub
注解
如果属性为 true.,则会ProfileAutoSaving在页面执行结束时引发该ProfileManager.AutomaticSaveEnabled事件。 可以使用全局事件访问 ProfileAutoSaving ASP.NET 应用程序的 Profile_ProfileAutoSaving Global.asax 文件中类的事件ProfileModule,如本主题的示例所示。
该方法 SettingsBase.Save 检查 IsDirty 用户配置文件中每个 SettingsPropertyValue 属性的属性值,以确定由基元类型、字符串或 DateTime 对象构成的属性是否已更改。 该方法 Save 无法显式确定自定义类是否已更改。 可以使用 ProfileAutoSaving 该事件来确定自定义对象是否已更改,然后继续自动保存已修改的对象,或者在未修改任何对象的情况下取消自动保存。
若要取消自动配置文件保存操作,请将 ContinueWithProfileAutoSave 属性设置为 false 事件 ProfileAutoSaving 中;否则,将该 ContinueWithProfileAutoSave 属性设置为 true。
事件可能有多个订阅者 ProfileAutoSaving 。 将使用 ProfileModule 属性设置为的最后一个值 ContinueWithProfileAutoSave 。 因此,建议在取消或继续自动保存时显式设置 ContinueWithProfileAutoSave 属性 ProfileAutoSaving ,因为可能需要覆盖早期订阅者设置的值。