Export (0) Print
Expand All

How to: Remove User Entries from the Personalization Store

In an ASP.NET Web application that uses personalization, there are some circumstances in which you might need to remove entries from the personalization store. How to: Enable Users to Clear Personalization State shows the simplest approach, which is to expose the ResetPersonalizationState method through a control on the page so that individual users can remove all personalization data that pertains to them. However, if you need to manage personalization data of other, multiple users, you must use the various methods of the PersonalizationAdministration class.

NoteNote

Only administrators of the page should be granted access to the methods of the PersonalizationAdministration class.

To remove an individual user state from the personalization store

  1. In a part of the Web application that is available only to administrators, such as an ASP.NET page or a user control, create a set of controls to receive user input and send it to the server.

    The example in this procedure uses a TextBox control and a Button control.

  2. In the appropriate event handler, call the System.Web.UI.WebControls.WebParts.PersonalizationAdministration.ResetUserState(System.String,System.String) method with the relative path to the Web application in question and the user name as parameters, as shown in the following example.

    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");
        }
    }
    
    

To remove a group of users from the personalization store

  1. In a part of the Web application that is available only to administrators, create a set of controls to receive user input and send it to the server.

    The example in this procedure uses a TextBox control and a Button control.

  2. In the appropriate event handler, call the System.Web.UI.WebControls.WebParts.PersonalizationAdministration.ResetUserState(System.String,System.String[]) method with the relative path to the Web application in question and a list of user names as parameters, as shown in the following example.

    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.");
    }
    
    

To remove all inactive users from the personalization store

  1. In a part of the Web application that is only available to administrators, create a Calendar and a Button control.

  2. In the appropriate event handler, call the System.Web.UI.WebControls.WebParts.PersonalizationAdministration.ResetInactiveUserState(System.String,System.DateTime) method with the relative path to the Web application in question and a list of user names as parameters, as shown in the following example.

    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.");
    }
    
    

See Also

Community Additions

ADD
Show:
© 2015 Microsoft