Many customers most of the time wants customize Sharepoint.
We know it and I write about it mostly.
So we are here for another one kind of customization:
Error Pages
We have many ways to customize error pages in SharePoint 2010.
The better way IMHO is to create a site feature and enable it when we create the sharepoint web application.
But what do we need to change the error pages when the web application is already created?
We can do it in two ways:
- by a console application
- by powershell
When I need to do this kind of works I like to use Powershell for many reasons: no project, compilation less, typeless, easy, smart, etc …
The class that can does this jobs is:
Microsoft.SharePoint.Administration.SPWebApplication
The code explains by itself:
- clear
-
- $siteUrl = Read-Host -Prompt "Url Web Application: "
-
- if ($siteUrl.Length -ile 0) {
- $siteUrl = "http://win-7iu1bqtgj2n:17927/"
- }
-
- $site = Get-SPSite $siteUrl -Limit All
-
- if (!$site) {
- return
- }
-
- $spWebApp = $site.WebApplication
-
- if (!$spWebApp) {
- return
- }
-
- try {
- # Output the newly assigned application page.
- $spWebApp.UpdateMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::Error, "/_layouts/MyPortal/error.aspx")
- $spWebApp.UpdateMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::AccessDenied, "/_layouts/MyPortal/error.aspx")
- $spWebApp.Update()
- }
- catch [System.Exception] {
- Write-Host $_ | fl * -Force
- }
-
- Write-Host "Press any key...";
- Read-Host
the most important lines of code are:
$spWebApp.UpdateMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::Error,"/_layouts/MyPortal/error.aspx")
$spWebApp.UpdateMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::AccessDenied, "/_layouts/MyPortal/error.aspx")
the UpdateMappedPage method writes in the SharePoint content database the information about the redirection in case of:
- None
- AccessDenied
- Confirmation
- Error
- Login
- RequestAccess
- Signout
- WebDeleted
bye
This comment has been removed by the author.
ReplyDeleteFazio, im not sure if the above script worked for you, but this line [Microsoft.SharePoint.Administration.SPWebApplication].SPCustomPage::AccessDenied , should be
ReplyDelete[Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::AccessDenied to work. You may have to correct your post
Tnx Kamus I pasted a wrong script
Delete