Set Permissions on SharePoint Application Pages

4.5k Views Asked by At

I have developed a number of application pages using visual studio 2010 and deployed them on SharePoint 2010.

All the pages have been extended from LayoutsPageBase.

Currently all the application pages are accessible by any authenticated users. However I would like to allow certain groups/permission to access these pages and disallow access for other groups/permissions.

My question:

How can I set the permissions for application pages to be accessible only by certain groups on the SharePoint level and on the code level?

1

There are 1 best solutions below

2
Rich Bennema On

Override a combination of these properties from LayoutsPageBase:

These properties are used by the CheckRights method to grant or deny access to an application page.

If you need something more specific than these properties offer, set RightsCheckModes to None and then write your own code that throws the following exception if the user should not have access:

SPUtility.HandleAccessDenied((Exception) new UnauthorizedAccessException());

Following the convention of the LayoutsPageBase class, this custom code should be called by your override of either the OnLoadComplete or OnPreInit events.