Search This Blog

Saturday, January 31, 2015

Difference between SPWeb.Users, SPWeb.AllUsers, SPWeb.SiteUsers


SiteUsers,  AllUsers and  Users are properties of SPWeb Object. But looking to this properties name,  its not easy to understand their’s scope.  So below is description about this properties:-

  1. SPWeb.Users :- This represents the collection of users or user objects who have been explicitly assigned permissions in the Web site . This does not return users who have access through a group.
  2. SPWeb.AllUsers :-This gives us the collection of user objects who are either members of the site collection or who have atleast navigated to the site as authenticated members of a domain group in the site.
  3. SPWeb.SiteUsers :- This is the collection of all users that belong to the site collection
Note :
SiteUsers > AllUsers > Users 
  1. Users => explicitly provide a user permission to the site 
  2. AllUsers => Users that have accessed the site via some group membership + Users 
  3. SiteUsers => AllUsers for all subsites + site collection admins


Code:
SPWeb web = SPContext.Current.Web;
SPUserCollection c1 = web.Users;
SPUserCollection c2 = web.AllUsers;
SPUserCollection c3 = web.SiteUsers;

No comments:

Post a Comment