Ashok Raja's Blog
Category : SharePoint 2013 Tips
Related Content
View All Tips

Provide your feed back about this tip

SharePoint 2010 and SharePoint 2013 Books and Tutorials , tips and tricks , Articles, News and Events for SharePoint Community shared by Ashok Raja . T
ARGUMENT.value = eventArgument; theForm.submit(); } } //]]>
Ashok Raja's Blog
KoSpJs (Knockout Js for SharePoint) is a SharePoint targeted data binding handler extension to Knockout Js, a highly popular JavaScript library based on MVVM pattern. KoSpJs acts a Knockout Js data binder and formatter for json data retrieved from SharePoint List . . . .
Keep an eye on my blog to get updated on real world SharePoint articles, recent books and tutorials on SharePoint 2013 and SharePoint 2010 and to get notified on events and happenings around SharePoint world.
The source code for this series of articles on SharePoint Single Page app built with Angular 2, SP PnP Js Core and Webpack is available in Github for download. Once you have downloaded the files or ha ...read more
Just like any other typical Angular 2 project with webpack, package and build system in this project has two separate webpack configuration files apart from a common configuration file shared by both ...read more
Routing is one of the key aspects of any Single Page App. This article talks about the routing aspects of Angular2 Single Page Application that is deployed inside the SitePages document library of Sha ...read more
This is one of the must have books for emerging Architects in Microsoft Platform. This .net technology guide for business applications talks in details about when to use what kind of Servers and appli ...read more
Category :   Architecture, MS Architect
This book on Windows Server 2012 R2 gives an over view of enhancements and new features available in Windows 2012 R2. Although this book is intended for Admins, this is a good read to know about basic ...read more
Category :   Windows 2012 R2
This book describes the performance issues related to Fine grained permissions like Item level permission, column level permission and folder level permission in SharePoint Lists ...read more
Category :   SharePoint 2010, SharePoint 2013
By default, SharePoint 2013 REST API returns output as Atom XML and there is no option to return data as JSON unless appropriate headers as passed with the request ...read more
Category :   SharePoint 2013
This article explains the similarities and differences associated with creating and provisioning of a custom pagelayout and a custom page in SharePoint with visual studio ...read more
Category :   SharePoint 2013, SharePoint 2010
The steps involved in creating and provisioning a custom page in SharePoint is almost same as that of creating and provisioning a custom page layout ...read more
Category :   SharePoint 2013, SharePoint 2010

Python, which doesn’t require much of introduction as it is one of the more powerful language which can be used for both device level programming to modern web application ...read more
Category :   Python
Although SAP suggests Eclipse to develop SAP UI 5 aka Open UI 5 applications, you can develop your SAP UI 5 applications in Visual Studio or any other environment that supports JavaScript ...read more
Category :   SAP UI5, Open UI5
This repeated notification of system cannot find the drive specified would be thrown if you install the SharePoint 2013 pre-requisites by mounting an ISO file from the local file system ...read more
Category :   SharePoint 2013

Block Users from accessing the Site in SharePoint 2013 by Access Denied Web Part - Ashok Raja's Blog
Ashok Raja's Blog
Block Users from accessing the Site in SharePoint 2013 by Access Denied Web Part
by Ashok Raja T 22. December 2012 11:26

In this blog post we can see how to block a User or User Group from Accessing a Share Point 2013 or Share Point 2010 site without disturbing the security permission. This Access Denied web part can also be configured to be used as an URL redirect web part by providing custom redirect URL as an input parameter.

Access denied web part has 4 custom properties which can be configured via web part properties page. The below are the details about the properties

Properties

Sl.NoProperty NameRemarks
1UserNamesAccepts User names (login name) as comma separated Values
2UserGroupsAccepts Share Point User Groups as comma separated Values
3RedirectUrlThe URL to which the user has to be redirected after blocking the user. If left blank, the user will be redirected to default SharePoint Access Denied page.
4BlockingModeCan be set to UserGroup or UserName
5IncludeSiteCollectionAdminIf Un-Checked (Default state) , the blocking option set wont restrict Site Collection Admins from accessing this page. If you have to restrict Site Collection Admins too then set this property to true.

wp settings

The web part code file contains 2 core methods named as IsMemberOfUserGroup and isBlockedUser which blocks the individual users or all users under a particular SharePoint User Group or groups based on the blocking mode option selected. Find below the code snippet which validates User and User Group.

 /// <summary>
 /// Determines whether user is member of specified user groups.
 /// </summary>
 /// <param name="userGroups">The user groups.</param>
 /// <returns>
 ///   <c>true</c> if [is member of user group] [the specified user groups]; otherwise, <c>false</c>.
 /// </returns>
 private bool IsMemberOfUserGroup(string userGroups)
 {
     if (string.IsNullOrEmpty(userGroups))
         return false;
     SPWeb web = SPContext.Current.Web;
     string[] Groups = userGroups.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
     if (Groups.Length == 0)
         return false;
     foreach (string item in Groups)
     {
         if (item.Trim().Length == 0)
             continue;
         int groupId = web.Groups[item].ID;
         if (web.IsCurrentUserMemberOfGroup(groupId))
             return true;
     }
     return false;
 }
 
 
 /// <summary>
 /// Determines whether user account is blocked.
 /// </summary>
 /// <param name="userAccounts">The user accounts.</param>
 /// <returns>
 ///   <c>true</c> if [is blocked user] [the specified user accounts]; otherwise, <c>false</c>.
 /// </returns>
 private bool isBlockedUser(string userAccounts)
 {
     if (string.IsNullOrEmpty(userAccounts))
         return false;
     string[] users = userAccounts.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
     if (users.Length == 0)
         return false;
 
     SPUser usr = SPContext.Current.Web.CurrentUser;
     if (usr == null || string.IsNullOrEmpty(usr.LoginName))
         return true;
 
     string loggedInUser = usr.LoginName.ToLower();
     if (loggedInUser.Contains("|"))
         loggedInUser = loggedInUser.Split('|')[1];
     foreach (string user in users)
     {
         if (user.Trim().ToLower() == loggedInUser)
             return true;
     }
     return false;
 }

Note : This post contains downloadable sample code for both SharePoint 2013 and SharePoint 2010.
blog comments powered by Disqus