HOW TO:從個人化存放區移除使用者項目
更新:2007 年 11 月
在使用個人化的 ASP.NET Web 應用程式中,您可能會遇到一些情況需要從個人化存放區移除項目。HOW TO:讓使用者清除個人化狀態示範了最簡單的方式,亦即透過網頁上的控制項來公開 (Expose) ResetPersonalizationState 方法,讓個別使用者可以移除與本身相關的所有個人化資料。但是,如果您需要管理其他多個使用者的個人化資料,就必須使用 PersonalizationAdministration 類別 (Class) 的不同方法。
![]() |
---|
只有網頁的系統管理員才應該獲得 PersonalizationAdministration 類別之方法的存取權。 |
若要從個人化存放區移除個別使用者狀態
在僅限系統管理員使用的 Web 應用程式的一部分中,例如 ASP.NET 網頁或使用者控制項,建立一組控制項來接收使用者的輸入並加以傳送給伺服器。
在適當的事件處理常式中,將未定的 Web 應用程式之相對路徑和使用者名稱當做參數來呼叫 PersonalizationAdministration.ResetUserState 方法,如下列範例所示。
Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Verify that the text box txtUser is not empty. If (txtUser.Text.Length < 1) Then Response.Write("You must enter a user name.") End If Return ' Reset the user. If (Not PersonalizationAdministration.ResetUserState("~/Default.aspx", txtUser.Text)) Then Response.Write("The user could not be found or the user has not personalized this page.") End If End Sub
protected void btnClear_Click(object sender, EventArgs e) { // Verify that the text box is not empty. if (txtUser.Text.Length < 1) { Response.Write("You must enter a user name."); return; } // Reset the user. if (! PersonalizationAdministration.ResetUserState("~/Default.aspx", txtUser.Text)) { Response.Write("The user could not be found or the user has not personalized this page"); } }
若要從個人化存放區移除使用者群組
在僅限系統管理員使用的 Web 應用程式的一部分中,建立一組控制項來接收使用者的輸入並加以傳送給伺服器。
在適當的事件處理常式中,將未定的 Web 應用程式之相對路徑和使用者名稱清單當做參數來呼叫 PersonalizationAdministration.ResetUserState 方法,如下列範例所示。
Protected Sub btnClearList_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Verify that the text box is not empty. If (txtUser.Text.Length < 1) Then Response.Write("You must enter at least one user name.") Return End If ' Extract the list of users. Dim users As Array users = txtUserList.Text.Split(" ,;".ToCharArray()) ' Reset the users. Dim RowsReset As Integer RowsReset = PersonalizationAdministration.ResetUserState("~/Default.aspx", users) Response.Write(RowsReset + "of " + users.Length + " users found and removed.") End Sub
protected void btnClearList_Click(object sender, EventArgs e) { // Verify that the text box is not empty. if (txtUser.Text.Length < 1) { Response.Write("You must enter at least one user name."); return; } // Reset the users. string[] users = txtUserList.Text.Split(" ,;".ToCharArray()); int RowsReset = PersonalizationAdministration.ResetUserState("~/Default.aspx", users); Response.Write(RowsReset + "of " + users.Length + " users found and removed."); }
若要從個人化存放區移除所有非作用中的使用者
在適當的事件處理常式中,將未定的 Web 應用程式之相對路徑和使用者名稱清單當做參數來呼叫 PersonalizationAdministration.ResetInactiveUserState 方法,如下列範例所示。
Protected Sub btnClearInactive_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Verify that a date is selected. If (calInactive.SelectedDate = DateTime.MinValue) Then Response.Write("You must select a date.") Return End If ' Reset all users inactive since the selected date. Dim RowsReset As Integer RowsReset = PersonalizationAdministration.ResetInactiveUserState("~/Default.aspx", calInactive.SelectedDate) Response.Write(RowsReset + " inactive users removed.") End Sub
protected void btnClearInactive_Click(object sender, EventArgs e) { // Verify that a date is selected. if (calInactive.SelectedDate == DateTime.MinValue) { Response.Write("You must select a date."); return; } // Reset all users inactive since the selected date. int RowsReset = PersonalizationAdministration.ResetInactiveUserState("~/Default.aspx", calInactive.SelectedDate); Response.Write(RowsReset + " inactive users removed."); }
請參閱
工作
參考
System.Web.UI.WebControls.WebParts