Navigate Up
Sign In
Supporters of Developer
Web

Customizing AccessDenied, SignOut and other pages in SharePoint 2010 using PowerShell

Item is currently unrated. Press SHIFT+ENTER to rate this item.1 star selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+ESCAPE to leave rating submit mode.2 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.3 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.4 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.5 stars selected. Press SHIFT+ENTER to submit. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.

 

When building a custom solution in SharePoint, whether intranet or public facing, you often need to balance out-of-the-box functionality with the custom look and feel your customer is asking for.

There are number of out-of-the-box system pages which SharePoint uses to display upon various events. For example; AccessDenied.aspx page is displayed when a user is trying to access the resource they don't have permission to. Signout.aspx is a common one – displayed when user chooses to sign out.

A few others include:
Confirmation.aspx
Error.aspx
Login.aspx
ReqAcc.aspx
WebDeleted.aspx

In SharePoint 2010 there is an elegant way to customize what user's will see without changing the original files. Here are the steps:

1. First you can copy an existing page from the Template/Layouts, in our case we'll use AccessDenied.aspx.

You can give it any name. If you’re using a Visual Studio solution simply add this new file to your solution structure under Layouts mapped folder.

2. Make any desired changes to the newly created page. If you made a copy of an existing page, remember that it’s referencing the original assembly and you still need to follow the structure outlined in the page placeholders to avoid the page erroring out.

Alternately, you can create your own page in VS2010 which can reference its own assembly.

3. Assuming the page has been deployed to the layouts folder. Execute the following PowerShell to set it as a default page for the role, in our case AccessDenied page role.

PS C:\Users\Administrator> $site = get-spsite "http://intranet.contoso.com"
PS C:\Users\Administrator> $webApp = $site.WebApplication
PS C:\Users\Administrator> $webapp.UpdateMappedPage(1, "/_layouts/AccessDeniedNew.aspx")
True
PS C:\Users\Administrator> $webapp.Update()
PS C:\Users\Administrator>

In here, the value of “1″ in UpdateMappedPage, specifies a reference to an enumeration value for other page roles available, see SPCustomPage for more info.

4. We’re set. Since we’re testing AccessDenied page, I’m going to log in as a reader and access “Site collection administrators” page by URL.

As a result I am getting my customized AccessDenied page:

2011-10-11-CustomAccessDenied-01.png

Notice that the URL of the page still remains the same AccessDenied.aspx and not our AccessDeniedNew.aspx – however, the content is different.

5. To reverse the customization, execute:

PS C:\Users\Administrator> $webapp.UpdateMappedPage(1, $null)
True
PS C:\Users\Administrator> $webapp.Update()
PS C:\Users\Administrator>

NOTE: The custom page must always be hosted in _layouts, otherwise the UpdateMappedPage will fail. If you need to show your content page as a result – you can execute a redirect from the custom page in _layouts to your content page.

Enjoy!

This article was originally posted on Yaroslav's blog at http://www.sharemuch.com/

Categories: Visual Studio 2010; PowerShell; MOSS; WSS; 2007; 2010

Comments

PerS

Set-SPCustomLayoutsPage

Isn't it better to use Set-SPCustomLayoutsPage ?

Posted 24-Oct-2011 by PerS
Swapna Thomas

This is wht v looked for

Good pointer for customization of default sharepoint page .
Thanks it helped

Posted 09-Dec-2011 by Swapna Thomas
BGM

Doesn't seem to work

Well, I have my custom AccessDenied page in layouts, but it never loads. Instead it always reloads the default - as if the powershell script didn't have any effect, although the one statement *did* return true like it should.

Posted 12-Jan-2013 by BGM

Notify me of comments to this article

E-mail:
   

Add Comment

Title:

 
Comment:
Email:

   


Name:

 
Url: