Sharepoint 2010,根据当前用户确定对 SPListItem 的访问权限

发布于 2024-11-17 13:57:21 字数 374 浏览 6 评论 0原文

我正在使用 CAML Queryy 来获取包含 ContentType 的所有列表项,但我还需要知道当前用户是否有权查看该文件。

那部分我不知道如何检查它。

我使用此示例作为如何获取与内容类型相关的项目的参考。

https://sharepoint.stackexchange.com/ questions/14566/how-to-find-all-documents-of-a-certain-content-type

谢谢。

i am using a CAML Queryy to get all the list items that are cotains a ContentType, but i also need to know if the Current user, has permissions to see that file.

That part i do not know how can i check it.

i use this exmpla as reference of how to get the items related to a content type.

https://sharepoint.stackexchange.com/questions/14566/how-to-find-all-documents-of-a-certain-content-type

Thanks.

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

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

发布评论

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

评论(1

终陌 2024-11-24 13:57:21

默认情况下,在 SharePoint 中,我们的代码会在用户执行 Web 请求时模拟运行。因此,CAML 查询返回的项目已经经过安全修整。这意味着,结果集仅包含允许当前用户“查看”的项目。

在某些情况下,您需要使用系统权限执行 CAML 查询。为此,必须使用系统帐户令牌打开 SPSite 对象:

using (SPSite elevatedSite = new SPSite("http://server-url", SPUserToken.SystemAccount))
{
  // open web; list; 
  // execute caml query with system account priveliges.
}

在这种情况下,您可以使用 DoesUserHavePermissions 方法检查/确保某个列表项的权限:

SPListItem item = //...
if (item.DoesUserHavePermissions(SPContext.Current.Web.CurrentUser, SPBasePermissions.ViewListItems))
{
  // futher actions if user has permission goes here.
}

重要需要注意的是,您必须使用 SPUser 参数调用 DoesUserHavePermissions 的重载。没有的过载将使用站点的“当前用户”。这是自使用系统帐户令牌打开站点以来的系统帐户。

Per default in SharePoint our code runs impersonated as the user executing the web request. Thus the items returned by the CAML query are already security trimmed. Meaning, the result set only contains items the current user is allowed to "see".

Under some circumstances you are required to execute the CAML query with system priveliges. To do so the SPSite object has to be opend with the system account token:

using (SPSite elevatedSite = new SPSite("http://server-url", SPUserToken.SystemAccount))
{
  // open web; list; 
  // execute caml query with system account priveliges.
}

In that case you could check / ensure permissions on a certain list item with the method DoesUserHavePermissions:

SPListItem item = //...
if (item.DoesUserHavePermissions(SPContext.Current.Web.CurrentUser, SPBasePermissions.ViewListItems))
{
  // futher actions if user has permission goes here.
}

Important to note is that you have to call the overload of the DoesUserHavePermissions with the SPUser argument. The overload without will use the "current user" of the site. Which is the system account since the site was opened with the system account token.

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