Wednesday, July 10, 2013

Customize Access Denied Page



In this post we are going to see how we can customize the access denied page in SharePoint. Many times we wish we could display some other friendly message than the one displayed by default.



First we need to understand that this is a page under layouts folder.

So we also need to create an application page. Open a project and add an item. Select application page as an item to add.



Now go to the layouts folder under template in 14 hive.

Locate accessdenied.aspx



Open the file in notepad.

Copy the HTML from the accessdenied to our customaccessdenied page.



As of not to test that we are in a right path, build the project and deploy the solution to the SharePoint site.

Once deployed, check that it is deployed to layouts folder and then open the site and in URL type _layouts/customaccessdeniedpage.aspx





Change two contents like this and then we will deploy again to see that changes are reflected.



Deploy the solution and check the page again.



As you can see changes are reflected.

But now the question is how we can actually bind this page to Web Application so that on access denied error is taken to this page and not to the default access denied page.

Here is a powershell command for this. Execute this and check the access denied. You should be good to go.

 $site = get-spsite "site url"

$webApp = $site.WebApplication


$webapp.UpdateMappedPage(1, "/_layouts/CustomAccessDeniedPage.aspx")




$webapp.Update()



1 refers to the access denied page as per the enumeration defined in SPCustomPage. Same way there are enumerations also for the logout, sing in page etc.

If you want to roll back changes, then


$webapp.UpdateMappedPage(1, $null)




$webapp.Update()













 
Just remember that this settings can only be done at web application level and not to the site collection level.


1 comment:

Anonymous said...

But the same is not working in sharepoint 2013.




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com