Sunday, January 24, 2010

DoesUserHavePermissions ?

I just finished writing a web part that I wanted to put on the home page of the Colorado SharePoint Users Group site (http://www.cospug.com). The web parts primary function is to allow people with the appropriate permission to use it to enter a Tweet into a special list that I made that will send tweets to Twitter. I wanted to use the permissions of the list to control if the user saw the web part or not. I found the 'DoesUserHavePermissions' and thought this would be a slam dunk, but when I used it, I found that if the user didn't have the appropriate permissions, it would throw up an 'Access Denied' page instead of returning a Boolean value of 'False'. After some thinking, I decided to use the 'RunWithElevatedPrivileges' and run this code inside a privileged delegate. This was the missing element. Works like a charm now.

0 comments: