Skip to main content

SharePoint2010 Replace AccessDenied.aspx, Confirmation.aspx and other page with our own custom page



In sharePoint2010, we can replace the list of the following page with our own custom page.
  1. AccessDenied.aspx
  2. Confirmation.aspx
  3. Error.aspx
  4. Login.aspx
  5. ReqAcc.aspx
  6. SignOut.aspx
  7. WebDeleted.aspx


For replace the default list of pages as mentioned in above. We have a class SPWebApplication Under namespace Microsoft.SharePoint.Administration. SPWebApplication class have a SPCustomPage enum which has a following values.

public enum SPCustomPage
        {
            // Summary:
            //     Specifies that no page will be replaced with a custom page.
            None = 0,
            //
            // Summary:
            //     Specifies that the AccessDenied.aspx page will be replaced with a custom
            //     page.
            AccessDenied = 1,
            //
            // Summary:
            //     Specifies that the Confirmation.aspx page will be replaced with a custom
            //     page.
            Confirmation = 2,
            //
            // Summary:
            //     Specifies that the Error.aspx page will be replaced with a custom page.
            Error = 3,
            //
            // Summary:
            //     Specifies that the Login.aspx page will be replaced with a custom page.
            Login = 4,
            //
            // Summary:
            //     Specifies that the ReqAcc.aspx page will be replaced with a custom page.
            RequestAccess = 5,
            //
            // Summary:
            //     Specifies that the Signout.aspx page will be replaced with a custom page.
            Signout = 6,
            //
            // Summary:
            //     Specifies that the WebDeleted.aspx page will be replaced with a custom page.
            WebDeleted = 7,
        }

On Feature activation we can update the SharePoint2010 page with our own custom page. As mentioned in bellow.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            const string CustomAccessDeniedPage = "/_layouts/MyAccessDenied.aspx";
            const string CustomConfirmationPage = "/_layouts/MyConfirmation.aspx";
            const string CustomErrorPage = "/_layouts/MyAccessDenied.aspx";
            const string CustomLoginPage = "/_layouts/MyAccessDenied.aspx";
            const string CustomReqAccPage = "/_layouts/MyAccessDenied.aspx";
            const string CustomSignOutPage = "/_layouts/MyAccessDenied.aspx";
            const string CustomWebDeletedPage = "/_layouts/MyAccessDenied.aspx";

            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
            if (webApp != null)
            {
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied, CustomAccessDeniedPage))
                {
                    throw new ApplicationException("Cannot create the custom access denied mapping.");
                }

                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Confirmation, CustomConfirmationPage))
                {
                    throw new ApplicationException("Cannot create the custom Confirmation mapping.");
                }
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, CustomErrorPage))
                {
                    throw new ApplicationException("Cannot create the custom Error mapping.");
                }
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Login, CustomLoginPage))
                {
                    throw new ApplicationException("Cannot create the custom Login mapping.");
                }
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.RequestAccess, CustomReqAccPage))
                {
                    throw new ApplicationException("Cannot create the custom RequestAccess mapping.");
                }
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Signout, CustomSignOutPage))
                {
                    throw new ApplicationException("Cannot create the custom Signout mapping.");
                }
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.WebDeleted, CustomWebDeletedPage))
                {
                    throw new ApplicationException("Cannot create the custom  WebDeleted mapping.");
                }
                webApp.Update(true);

            }
        }


        // Uncomment the method below to handle the event raised before a feature is deactivated.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            const string AccessDeniedPage = "/_layouts/AccessDenied.aspx";
            const string ConfirmationPage = "/_layouts/Confirmation.aspx";
            const string ErrorPage = "/_layouts/Error.aspx";
            const string LoginPage = "/_layouts/Login.aspx";
            const string ReqAccPage = "/_layouts/ReqAcc.aspx";
            const string SignOutPage = "/_layouts/SignOut.aspx";
            const string WebDeletedPage = "/_layouts/WebDeleted.aspx";

            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
            if (webApp != null)
            {
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied,
                    AccessDeniedPage))
                {
                    throw new ApplicationException("Cannot create the access denied mapping.");
                }

                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Confirmation, ConfirmationPage))
                {
                    throw new ApplicationException("Cannot create the access denied mapping.");
                }
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, ErrorPage))
                {
                    throw new ApplicationException("Cannot create the access denied mapping.");
                }
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Login, LoginPage))
                {
                    throw new ApplicationException("Cannot create the access denied mapping.");
                }
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.RequestAccess, ReqAccPage))
                {
                    throw new ApplicationException("Cannot create the access denied mapping.");
                }
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Signout, SignOutPage))
                {
                    throw new ApplicationException("Cannot create the access denied mapping.");
                }
                if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.WebDeleted, WebDeletedPage))
                {
                    throw new ApplicationException("Cannot create the access denied mapping.");
                } 

                webApp.Update(true);

            }
        }




Comments

  1. Hello !
    It is very intresting post. Can you show me your
    MyAccessDenied.aspx ? I want to display on MyAccessDenied.aspx information about owners of site and i have error - > cant display page
    regards

    ReplyDelete
  2. Hi,
    You just need to copy the Access Dined page from the 14 hive location "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\AccessDenied.aspx" and modify the page text as well as the name of the page and then apply the above code in my case "MyAccessDenied.aspx".

    ReplyDelete
  3. Is it Possible to set it for single site collection. Instead of entire web application?

    ReplyDelete
    Replies
    1. It is not possible to set this for a single site collection.

      Delete
  4. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

SharePoint RPC Protocols Examples Using OWSSVR.DLL

What is SharePoint RPC Protocols? Part 1 This reference includes information about the methods and usage of SharePoint Foundation Remote Procedure Call (RPC) protocol. This protocol can be used in Win32-based applications or in ASPX applications to make HTTP POST requests to the server. Methods in this protocol that do not modify the contents of the database can also be used in URL protocol to make HTTP GET requests. Definition taken from http://msdn.microsoft.com/en-us/library/ms448359.aspx You will find the OWSSVR.DLL in SharePoint 2010 Server Physical Path: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI and MOSS C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI OWSSVR.DLL List of commands DialogView  Display ExportList GetProjSchema GetUsageBlob HitCounter RenderView To read more about the OWSSVR.DLL command Please read the URL Protocol from Microsoft Blog having a URL http://msdn.microsoft.com/en...

SharePoint 2013 Search Database Part 1

SharePoint 2013 Search architecture drastically change, as earlier in FS4SP 2010 we have 2 search applications “FASTContentSSA” and “FASTQuerySSA” and 7 total database in use. Following are the List of DB (FS4SP) FASTContentSSA Search Service Application DB Search Service Application Crawl Store DB Search Service Application Property Store DB FASTQuerySSA Search Service Application DB Search Service Application Crawl Store DB Search Service Application Property Store DB FASTSearchAdminDatabase : Fast Search Admin Database  In SharePoint 2013 search has only 1 Search Service application and 4 database in use. No property store database need any more, now the properties are directly stored inside the index component and all the index directly indexed to the physical system where FS4SP data comes from database as well as from the File system now data directly stored and indexed/ retried from the Physical disk because of this performance increase and search experien...

STS CryptographicException Error : Key set does not exist

Common mistakes Both SharePoint Site and SSO Site NOT running on the same application pool. Application pool identity user doesn’t have permission to access the certification.  Solution to this problem Set the same identity pool to  : 2. Be sure to grant rights to the certificate for the App Pool running the web service Start -> Run -> MMC File -> Add/Remove Snapin Add the Certificates Snap In Select Computer Account, then hit next Select Local Computer (the default), then click Finish On the left panel from Console Root, navigate to Certificates (Local Computer) -> Personal -> Certificates You're certificate will most likely be here. Right click on your certificate -> All Tasks -> Manage Private Keys Set you're private key settings here. Add app pool account Reset iis