ProfileModule.ProfileAutoSaving 事件

定义

在启用自动配置文件保存的情况下在页面执行结束时发生。

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

注解

ProfileAutoSaving如果 ProfileManager.AutomaticSaveEnabled 属性true为 ,则会在页面执行结束时引发 该事件。 可以使用全局 ProfileAutoSaving 事件 ProfileModule 访问 ASP.NET 应用程序的 Profile_ProfileAutoSaving Global.asax 文件中 类的 事件,如本主题的示例所示。

方法 SettingsBase.Save 检查 IsDirty 用户配置文件中每个 SettingsPropertyValue 属性的属性值,以确定由基元类型、字符串或 DateTime 对象组成的属性是否已更改。 方法 Save 无法显式确定自定义类是否已更改。 可以使用 ProfileAutoSaving 事件来确定自定义对象是否已更改,然后继续自动保存已修改的对象,或者在未修改对象时取消自动保存。

若要取消自动配置文件保存操作,请在 ContinueWithProfileAutoSave 事件中ProfileAutoSaving将 属性设置为 false ;否则,将 ContinueWithProfileAutoSave 属性设置为 true

事件可能有多个订阅者 ProfileAutoSavingProfileModule将使用属性设置为的最后一个值ContinueWithProfileAutoSave。 因此,无论是取消还是继续自动保存,都建议在 事件中ProfileAutoSaving显式设置 ContinueWithProfileAutoSave 属性,因为可能需要覆盖早期订阅者设置的值。

适用于

另请参阅