The complete list of base permissions that can be used with the class can be viewed on this page: SPBasePermissions. It is also possible to show or hide content based on user authentication using the AuthenticationRestrictions property of the class, which may be useful if you want to display a different set of links depending on if a user has been authenticated or is anonymous.
Below are some examples of base permissions that are more likely to be used to restrict content to specific users with the associated permission.
Show content to only a user with full permissions on the site:
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent1"
PermissionsString="ManageWeb"
runat="server">
ASP Controls or HTML included here will be visible only to users with full permission on the site.
</SharePoint:SPSecurityTrimmedControl>
Show content to only users who can manage lists
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent2"
PermissionsString="ManageLists"
runat="server">
ASP Users Controls or HTML included here will be visible only to users who have the Manage Lists permission.
</SharePoint:SPSecurityTrimmedControl>
Show Content to users with access to manage permissions
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent3"
PermissionsString="ManagePermissions"
runat="server">
ASP Users Controls or HTML included here will be visible only to users who can manage permissions.
</SharePoint:SPSecurityTrimmedControl>
Show Content to users who can Add, Edit or Delete List Items in the Current List
Multiple permission levels are separated by a comma. To allow the content to be displayed if a user has any one of the listed base permissions, the PermissionMode property should be included with the mode as “Any” (used in example below). The user must have all permissions listed if PermissionMode=”All” or is not specified. The Context is also set to restrict the permission mask to the current list (PermissionContext=”CurrentList”).
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent4"
PermissionsString="AddListItems, EditListItems, DeleteListItems"
PermissionMode=”Any”
PermissionContext=”CurrentList”
runat="server">
Content here will be displayed if a user has access to Add Edit or Delete list items.
</SharePoint:SPSecurityTrimmedControl>
Show a link to Anonymous (not authenticated) users only
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent5"
AuthenticationRestrictions=”AnonymousUsersOnly”
runat="server">
<a href=”/” >Link displayed for Anonymous Users Only</a>
</SharePoint:SPSecurityTrimmedControl>
Show a link to Authenticated users only
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent6"
AuthenticationRestrictions=”AuthenticatedUsersOnly”
runat="server">
<a href=”/” >Link displayed for Authenticated Users Only</a>
</SharePoint:SPSecurityTrimmedControl>
Some of the properties used in the examples above to customise use of the SPSecurityTrimmedControl class when restricting content for specific users are below:
- PermissionsString - A comma separated list of the base permissions that a user requires for the content to be displayed.
- AuthenticationRestrictions - Displays content based on the authentication status.
- PermissionContext - Sets the context of the permission mask (CurrentFolder, CurrentItem, CurrentList, CurrentSite, RootSite)
- PermissionMode - When multiple base permissions are provided, this property is used to specifies if all of the permissions are required, or any one similar to the use of “&&” (AND) or “||” (OR).
- Full list of SPSecurityTrimmedControl Members.
Related:
SharePoint: Show or Hide Content based on Permissions - This article demonstrates how to show a “View All Site Content” link to users with full permission on a site, or with access to Manage Lists on a site using SPSecurityTrimmedControl. It is placed in a Master Page using SharePoint Designer.
No comments:
Post a Comment