1

我有一个在 SharePoint 2007 上运行的类似购物车的应用程序。

我正在对列表项运行一个非常标准的更新程序:

            using (SPWeb web = site.OpenWeb())
            {
                web.AllowUnsafeUpdates = true;
                SPList list = web.Lists["Quotes"];
                SPListItem item = list.GetItemById(_id);
                item["Title"] = _quotename;
                item["RecipientName"] = _quotename;
                item["RecipientEmail"] = recipientemail;
                item["IsActive"] = true;
                item.Update();
                site.Dispose();
            }

此项目正确更新,但它短暂显示为由系统帐户修改。如果我等待一秒钟并刷新页面,它会再次显示为由 CurrentUser 修改。

这是一个问题,因为在 Page_Load 上,我正在检索标记为活动的项目并且被列为由 CurrentUser 修改。这意味着当用户更新他的列表时,当 PostBack 完成时,它显示他没有活动项目。

是 web.AllowUnsafeUpdates 吗?这是必要的,因为我之前遇到过安全错误。

我错过了什么?

4

2 回答 2

1

First off, it's not AllowUnsafeUpdates. This simply allows modifying of items from your code.

It's a bit hard to tell what's going on without understanding more of the flow of your application. I would suggest though that using Modified By to associate an item to a user may not be a great idea. This means, as you have discovered, that any modification by the system or even potentially an administrator will break that link.

I would store the current user in a custom field. That should solve your problem and would be a safer design choice.

于 2012-06-09T07:04:48.123 回答
0

可能有一些其他代码在事件接收器中运行并更新项目。因为事件接收器在系统用户帐户的上下文中运行,如果您从事件接收器更新项目,修改字段将显示:系统帐户已修改项目。

于 2012-06-11T07:29:18.760 回答