SharePoint 2013: Provisioning a custom error page

Hello everyone!

Today I wanted to share with you an example to how custom access denied page could be implemented and applied to a web application scope. In my case I wanted to list emails of all the people who has Full Control permissions set on the accessed web, either directly, or as a part of a SharePoint group.

For this to work I have used this building blocks:

  • Created a custom aspx page (markup only) which is based on original AccessDenied.aspx in SharePoint, so it also inherits from Microsoft.SharePoint.ApplicationPages.AccessDeniedPage
  • Created a web service that get called from custom page. It lists the users I need, constructs the HTML and returns that back to the page
  • A web application scoped feature with a little code to register/unregester our custom page
  • Profit!

Here is the code

WebApp-scoped feature

Let’s start with provisioning this time. I have my custom page inside a mapped folder in Visual Studio, as shown in the image below
VS1

Here is the code excerpt from the feature event receiver

Custom access denied page markup

Here is the mark up of custom access denied page. Note, I include the reference to jQuery file that I store within my solution – you just have to provide a path that works for you. Code is pretty self-explanatory – all the stuff is happening in getAccess JS function. Countdown function will redirect to the root in 30 seconds.

Web service code

I won’t cover setting up the markup of web service here, please refer to this post, part of it covers this. UlsLogging class implementation can be found here (or just delete the line).

The actual code of my web service code-behind is here:

That’s pretty much it, does the job for me 🙂

Thanks for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *