Monday, August 27, 2012

Tips to change SharePoint 2010 behavior without change out of box UI - Part II SPCustomLayoutsPage

Modifying the files that are installed by SharePoint is not supported to change the behavior of the SharePoint. As we discuss before, one of the best practices is to use the tagmapping functionality to instruct the parser to substitute a different derived type implementation whenever it encounters the type being mapped. It is quite useful to redirect SharePoint Out of box to customized one. However, this mechanism will be difficult if you need to customize the behavior of out of box application pages such as AccessDenied, Confirmation, Error, Login, RequestAccess, Signout and WebDeleted. In this blog, we will introduce the new SharePoint 2010 Powershell Set-SPCustomLayoutsPage that will replace application pages in layouts directory that is supported by Microsoft.

Here is the user case for our company - users want to customize the access denied page to have the following behavior and we also prefer to apply the same company branding to the page.

Include the following sentence You are requesting access to highly sensitive company content, which requires a business justification, and in some situations, approval from your supervisor(s). In order for your request to be properly and quickly assessed, please specify what project you are working on, the specific content in which you are interested, and (most importantly) why you need it.”
The solution provided by SharePoint 2010 is very simple and here are the steps. We use RequestAccess page as example.

1. Copy the access deny application page from layout folder and copy/modify to incorporate the change required including the branding
2. Deploy the custom Request Access page to custompages folder under layouts directory
3. Set custom page for SharePoint to use instead

Set-SPCustomLayoutsPage -Identity "RequestAccess" -RelativePath "/_layouts/custompages/reqacc.aspx" -WebApplication "{replace with web app url}"

Now the access denied page will use the custom one instead of the OoB one. You could verify what custom page SharePoint is using by typing the powershell Get-SPCustomLayoutsPage command.

You might also change it pro grammatically through IHttpModule or event receiver that might be fit into your use cases. If you need to have a different access denied page for different site collection, you might add logic to the custom page or createdifferent folder each site collection

In addition, if you need to display more information to the customized access denied page such as owner list, you could use server object model API.

No comments:

Post a Comment