Wednesday, September 13, 2017

Modifying the Access Denied Page in SharePoint 2010

In my company, all the requests for SharePoint has to come through the Help Desk. We had disabled the "Request Access" link by going to "Site Permissions" and selecting "Manage Access Request" and unchecking the "Allow access request".


This was solution to just hide the "Request Access" link on access denied page. But my requirement was to add the help desk information with Phone number and email address for which I had to create a new "Access Denied" page.


Following are the steps to do the same.
  • Login to your WFE server, go to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS
  • Create a folder called "CustomPages". [Note this is important because modifying the 14/15/16 hive is not recommended as the changes will be overridden when there is patching from Microsoft]
  • Copy the AccessDenied.aspx page from the step 1 to "CustomPages" folder and rename it to "CustomAccessDenied".
  • Open the CustomAccessDenied in notepad, Just above the <asp:HyperLink id="HLinkLoginAsAnother" ... add the line below
<p>To request access please contact the help desk xxx-xxx-xxxx or email xxx@xyz.com</p>



  • Save the file.
  • Now open the PowerShell Management Shell and type the command below
Get-SPCustomLayoutsPage –Identity "AccessDenied" -WebApplication "http://DEVWEBAPPLICATION



This shows the path for all the CustomLayoutPages like Access Denied, Error Page etc which will be blank as it will be default paths
  • To tell the SharePoint to use your new AccessDenied, run the following command
Set-SPCustomLayoutsPage -Identity "AccessDenied" -RelativePath "/_layouts/ExampleAccessDenied.aspx" -WebApplication


  • Execute Get-SPCutomLayoutsPage as below to see the effect

NOTE:
1. If you have multiple WFE, create the CustomPages folder and copy the file to other WFE servers as well
2. You don't have to run the command again in other WFE, but I have seen that you have to do an iisreset in other WFE(s) to tell the SharePoint to pick the new file.