Custom AccessDenied.aspx Access Denied Page for SharePoint 2010

First you will need to make a copy of the default layout page AccessDenied.aspx which is located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS

For example, you can call it AccessDeniedNew.aspx. This new page layout should stay in “LAYOUTS” folder.

Login to your server as a farm administrator. Start SharePoint 2010 Management Shell. Run the following code:

$site = get-spsite "http://YOUR_SITE_URL"
$webApp = $site.WebApplication
$webapp.UpdateMappedPage(1, "/_layouts/AccessDeniedNew.aspx")
$webapp.Update()

To switch back to the default page, you can use the following code

$site = get-spsite "http://YOUR_SITE_URL"
$webApp = $site.WebApplication
$webapp.UpdateMappedPage(1, $null)
$webapp.Update()

You can get more information about the custom page from Yaroslav’s blog

In the method of $webapp.UpdateMappedPage, 1 is for Access Denied Page. See the following table for other type of pages

AccessDenied = 1

Confirmation = 2

Error = 3

Login = 4

RequestAccess = 5

Signout = 6

WebDeleted = 7

You can use Set-SPCustomLayoutsPage and Get-SPCustomLayoutsPage to reach the same goal as well.

 

Read More

This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration Wizard, located on the Start menu in Microsoft SharePoint 2010 Products.

I got this error when I use Visual Studio 2010 to program some SharePoint 2010 stuff. It is a simple console program. This exception happens at the following line:

SPWebApplication webApplication = SPWebApplication.Lookup(new Uri("http://mysiteurl"));

Below is another error:

The Web application at http://mysiteurl could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

and this happens at line

SPSite site = new SPSite("http://mysiteurl");

Both of the errors have the same root cause.

Solution:

Right Click your project, Choose Properties. Go to tab “Build”, Change Platform Target from “x86” to “Any CPU”. Recompile your project and you will be all set to go.

Read More