Sharepoint farm administrators are powerful users who may perform administrative actions in Sharepoint farm (see SharePoint Farm Administrator account for more details). Sometime you may need to check whether or not current user is farm admin in order to allow or disallow specific actions. You may do that using SPFarm.CurrentUserIsAdministrator method. The problem however that it will work as expected only in context of Central administration web application (i.e. if page which calls this method is running in Central administration). If you will try to call this method from regular Sharepoint web application it will always return false even if current user is added to Farm administrations group on your farm - you may add users to Farm administrators using Central administration > Manage the farm administrators group:
In this case (when you need to call SPFarm.CurrentUserIsAdministrator from regular Sharepoint web application) you have to use overridden version of this method with boolean parameter:
allowContentApplicationAccess
true to make the check work in the content port of a Web application; otherwise, false.
i.e. like this:
bool isFarmAdmin = SPFarm.Local.CurrentUserIsAdministrator(true);
In this case method will work as expected i.e. return true if user is member of Farm administrators group and false otherwise.
No comments:
Post a Comment