使用 DataKeynames 时 Sharepoint 搜索失败

发布于 2024-08-05 23:56:14 字数 2279 浏览 2 评论 0原文

我们有一个使用搜索的 Sharepoint 网站。

我们收到以下错误:

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)

经过一些测试,我们发现当我们在 GridView 控件上使用 DateKeyNames 时会发生错误。

不知道为什么搜索、此错误和 DataKeyNames 之间应该有任何组合。

有什么想法吗?

更新:这里是一些代码

[Guid("8891224e-e830-4ffa-afbd-f789583d8d14")]
    public class TestErrorGridView : System.Web.UI.WebControls.WebParts.WebPart
    {
        Control ascxToAdd;
        public TestErrorGridView()
        {
        }

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

        }

        protected override void CreateChildControls()
        {


            base.CreateChildControls();
            Table test = new Table();
            TestBindObject t1 = new TestBindObject() { ID = 1, Name = "Test" };
            List<TestBindObject> l1 = new List<TestBindObject>();
            l1.Add(t1);
            SPGridView testGrid = new SPGridView() { AutoGenerateColumns = false};
            BoundField header = new BoundField();
            header.DataField = "ID";
            BoundField name = new BoundField();
            name.DataField = "Name";
            testGrid.Columns.Add(header);
            testGrid.Columns.Add(name);
            testGrid.DataSource = l1;
            testGrid.DataBind();
            // If you comment out this line search works
            testGrid.DataKeyNames = new string[] { "ID" };
            this.Controls.Add(testGrid);

            base.CreateChildControls();
            SPGridView testGrid = new SPGridView() { AutoGenerateColumns = false, EnableViewState=false };

            testGrid.DataKeyNames = new string[] { "testid" };  

            this.Controls.Add(testGrid);

        }
    }

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

更新

此错误发生在开发人员机器上,因此与集群中不同机器上的机器密钥不同无关。

一位开发人员安装了 MOSS,他没有收到错误消息。刚刚安装 WSS 的开发人员会收到此错误。

更新2

已将数据源添加到代码中

We have a Sharepoint site which uses search.

We get the following error:

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)

After a bit of testing we have found that the error occurs when we use DateKeyNames on a GridView control.

Not sure why there should be any combination between Search, this error and DataKeyNames.

Any ideas?

Update: Here is some code

[Guid("8891224e-e830-4ffa-afbd-f789583d8d14")]
    public class TestErrorGridView : System.Web.UI.WebControls.WebParts.WebPart
    {
        Control ascxToAdd;
        public TestErrorGridView()
        {
        }

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

        }

        protected override void CreateChildControls()
        {


            base.CreateChildControls();
            Table test = new Table();
            TestBindObject t1 = new TestBindObject() { ID = 1, Name = "Test" };
            List<TestBindObject> l1 = new List<TestBindObject>();
            l1.Add(t1);
            SPGridView testGrid = new SPGridView() { AutoGenerateColumns = false};
            BoundField header = new BoundField();
            header.DataField = "ID";
            BoundField name = new BoundField();
            name.DataField = "Name";
            testGrid.Columns.Add(header);
            testGrid.Columns.Add(name);
            testGrid.DataSource = l1;
            testGrid.DataBind();
            // If you comment out this line search works
            testGrid.DataKeyNames = new string[] { "ID" };
            this.Controls.Add(testGrid);

            base.CreateChildControls();
            SPGridView testGrid = new SPGridView() { AutoGenerateColumns = false, EnableViewState=false };

            testGrid.DataKeyNames = new string[] { "testid" };  

            this.Controls.Add(testGrid);

        }
    }

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

UPDATE

This error occurrs on the developer machines, so it is not realated to machine keys being different on different machines in a cluster.

One of the developers has MOSS installed, he does not get the error. The developers who have just WSS installed get the error.

UPDATE 2

Have added datasource to code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我偏爱纯白色 2024-08-12 23:56:14

我将在这里抛出一个猜测,因为您设置 GridView 数据源的代码也丢失了,但是这里...

它可能与您设置 GridView 属性的顺序有关。我的猜测是您需要按以下顺序设置它:

  1. 创建 GridView
  2. 设置 GridView 的数据源(以便它有数据)
  3. 设置 DataKeyNames
  4. 调用 GridView.DataBind()

步骤 3 和 4 是我不确定的步骤。您可能必须先进行 DataBind,然后设置 DataKeyNames。

I'm going to throw out a guess here since the code where you set the GridView's datasource is missing as well, but here goes...

It probably has something to do with the order in which you are setting the GridView's properties. My guess is that you need to set it in this order:

  1. Create your GridView
  2. Set the GridView's datasource (so that it has data)
  3. Set DataKeyNames
  4. Call GridView.DataBind()

Step 3 and 4 are the steps I am not sure about. You may have to DataBind and then set DataKeyNames.

烟酒忠诚 2024-08-12 23:56:14

我们最终通过遵循此链接中的示例解决了此问题:

http://msdn。 microsoft.com/en-us/library/bb466219.aspx

我认为这是绑定到数据表而不是列表,从而产生了差异。

Sharepoint 网格不允许自动生成列这一事实似乎是导致此问题的因素之一。

We eventually solved this by following the example in this link:

http://msdn.microsoft.com/en-us/library/bb466219.aspx

I think that is was binding to a data table rather than a list that made the difference.

The fact that Sharepoint grids do not allow autogenerated columns appears to be one of the factors leading to this problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文