SharePoint Users&AllUsers&SiteUsers

注意: 本文讨论基于SharePoint 2010, 其次文章比较罗嗦, 大神直接可以PASS.

序言

大家都知道SPWeb中有三个属性可以获取相关用户集合:

SPWeb.Users Gets the collection of user objects that are explicitly assigned permissions in the website.
SPWeb.AllUsers Gets the collection of user objects that represents all users who are either members of the site or who have browsed to the site as authenticated members of a domain group in the site.
SPWeb.SiteUsers Gets the collection of all users that belong to the site collection.

看文字描述大家都能理解, 但是具体系统中哪些用户或者用户组存储在里面可能还有点迷糊. 下面我们通过几个实验来分别看看里面是怎么样的.

第一回

当我们新建一个网站集的时候, 一般会将Domain中的Users组直接赋予网站集只读的权限(如下图所示).

20151103.01

这时候我们来看看这三个属性中的值是怎么样的:

20151103.02

此时, SPWeb.Users中没有数据, SPWeb.AllUsers和SPWeb.SiteUsers中的数量是一致的.

第二回

这时候当多个用户去访问该站点的时候, 又会怎么样呢?

20151103.03

此时, 跟"第一回"的情况类似, 访问网站集的用户都出现在SPWeb.AllUsers和SPWeb.SiteUsers中, 而SPWeb.Users中还是没有数据.

第三回

当对某个用户自定义权限或者新建一个SharePoint自定义用户组并且赋予某个用户权限的时候, 又会怎么样呢?

20151103.04

这时候我们发现"SPWeb.Users"的属性值已经发生了变化, 同样该用户出现在SPWeb.AllUsers和SPWeb.SiteUsers中.

SPWeb.EnsureUser

当通过EnsureUser方法将某个用户加到网站集的时候:

20151103.05

这时候我们会发现SPWeb.SiteUsers相比SPWeb.AllUsers多了一个用户.

结束

SPWeb.SiteUsers中存储的数据是最多的, 其次是SPWeb.AllUsers, 最后是SPWeb.Users. 大家觉得呢?

enjoy SharePoint

posted @ 2015-11-11 10:18  jns  阅读(325)  评论(0编辑  收藏  举报