Showing posts with label permission. Show all posts
Showing posts with label permission. Show all posts

Monday, April 22, 2013

UserProfileApplicationNotAvailableException_Logging error within SharePoint 2013

Recently while playing around with UserProfileManager, I came across a very strange issue where I couldn’t find much help on the internet. After some researching here and there, I finally found that the issue was just a permission issue. While trying to use UserProfileManager in my code, I was passing the SPServiceCOntext object to it and while creating an object of UPM, the error I was getting was

UserProfileApplicationNotAvailableException_Logging :: UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does not have 607c1325-164c-4da5-8bd0-e28be323a06c

The resolution of this is to assign Full Control permission to the User Profile Service in Central Administration. In my case, it was my account and as I gave it full control, it ran smoothly. Follow the screenshots for details.
Navigate to Central Administration > Application Management > Manage Service Applications and select User Profile Service

Click on Permissions

Add the account which runs the designated code.

Hope this helps someone.

Thursday, April 4, 2013

Programatically breaking inheritance and adding unique permission to List Items


Permission handling is something which makes SharePoint a favorite product within the industry. SharePoint has Permission levels in built for basic roles, however you can create your own permission levels and assign to Groups and then set those groups to access any site/library/list. Whenever a sub-site is created, it asks you if you want to inherit the permission from the parent site or want to create unique permissions. 

If you choose to inherit the permissions, it will copy the same set of permissions to the sub-site which will again be passed on to the lists/libraries you create. It may happen that for securing our content, we want to break this inheritance and want to assign unique permissions to restrict the users for certain actions and to make the content more secure. Inheritance can be broken manually using the Out of feature also and if you have a business logic in place, you can do it programmatically also. This blog post gives you code to break inheritance for items meeting certain criteria and assigning permissions to them explicitly. I am using ItemAdded() event receiver to do this. You can use it within workflow or any custom webpart as well.

SPGroup securityGroup = spWeb.SiteGroups["Security Group Name"]; 
SPRoleDefinition groupRole = spWeb.RoleDefinitions["Read"]; 

SPRoleAssignment roleAssign = new SPRoleAssignment(securityGroup); 
roleAssign.RoleDefinitionBindings.Add(groupRole); 

SPListItem listItem = spWeb.GetListItem("http://List Item URL"); 
listItem.BreakRoleInheritance(true); 
listItem.RoleAssegnments.Add(roleAssignment); 
listItem.Update();