R – SharePoint 2007 (wss) search and Unable to validate data Exception

sharepointwss-3.0

We have a problem with SharePoint's search box. Whenever we try to search for something we get:

Unable to validate data. at
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean
fEncrypt, Byte[] buf, Byte[] modifier,
Int32 start, Int32 length, IVType
ivType, Boolean useValidationSymAlgo)
at
System.Web.UI.ObjectStateFormatter.Deserialize(String
inputString) exeption.

Does any one know the reason for this exception, or a way to work around it?

New entry:

I'm using a SPGridView where i use the datakeys property in a web part. The webpart works, but we found that using the datakeys property breaks seach in that if you try to use the search textbox and click the seach button it gets this exception:

Unable to validate data. at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)

This is what i have tryed to do:

Make the gridview not spgridview and set autogenerate true (works)
Remove the datakeynames (works)
Test with a empty gridvew (failes)
Test with a non-empty gridview (failes)
Change Machine Keys (failes)
Turn of view state on the gridvew (failes)
Move the gridview ti a ascx file (failes)

I can't seem to figure this one out. Have enyone got this error and been able to work around it?

EDit 10.09.2009

This is the last code I tested. I used a MSDN excample as referance. I have also tried without Data table MSDN Example

public class TestErrorGridView : System.Web.UI.WebControls.WebParts.WebPart
{
    Control ascxToAdd;
    protected DataTable PropertyCollection = new DataTable();
    private DataColumn key;
    public TestErrorGridView()
    {
        key = PropertyCollection.Columns.Add("ID", typeof(string));
        PropertyCollection.Columns.Add("Name", typeof(string));
    }
    public void AddProperty(TestBindObject data)
    {
        DataRow newRow = PropertyCollection.Rows.Add();

        newRow["ID "] = data.ID;
        newRow["Name"] = data.Name;
    }
    public void BindGrid(SPGridView grid)
    {
        SPBoundField fldPropertyName = new SPBoundField();
        fldPropertyName.HeaderText = "ID";
        fldPropertyName.DataField = "ID";
        grid.Columns.Add(fldPropertyName);
        SPBoundField fldPropertyValue = new SPBoundField();
        fldPropertyValue.HeaderText = "Name";
        fldPropertyValue.DataField = "Name";
        grid.Columns.Add(fldPropertyValue);

        PropertyCollection.PrimaryKey = new DataColumn[] { key };
        grid.DataSource = PropertyCollection.DefaultView;
        grid.DataKeyNames = new string[] { key.ColumnName };
        grid.DataBind();
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

    }

    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        TestBindObject t1 = new TestBindObject() { ID = 1, Name = "Test3" };
        this.AddProperty(t1);

        SPGridView testGrid = new SPGridView() { AutoGenerateColumns = false };

        this.BindGrid(testGrid);


        this.Controls.Add(testGrid);

    }


}

[Serializable]
public class TestBindObject
{
    public int ID { get; set; }
    public string Name { get; set; }
}

Best Answer

From the error message I'd say that you are operating in a web-farm environment. Have you set the same machineKey in each of the SharePoint web.config files? See this link for a little more info.

Related Topic