1

If a user who don't have access to site, visits the site then he should see my custom page instead of Access Denied or Access Request page. Is this possible?

1 Answer 1

1

Yes it is! There is a very cool TechNet article on how to create a custom access denied page, however you need to have access a Front End server with a farm administrator account.

Apart from the Farm Adm account that also has the SharePoint_Shell_Access role for the farm configuration database, I think you would need some HTML/ASP knowledge.

Alternatively, you could create a HTTP Handler to intercept each request and redirect to your custom page. Check this blog post. And this is an code example of a Handler class.

public class CustomAccessDenied : ISPCustomRedirectHandler
{
    public string GetRedirectUrl(string key)
    {
        string serverRelativeUrl = string.Empty;

        var ctx = HttpContext.Current.Items["DefaultSPContext"];
        if (ctx != null)
        {
            serverRelativeUrl = ((SPContext)ctx).Web.ServerRelativeUrl;

            if (serverRelativeUrl.Equals("/"))
            {
                serverRelativeUrl = string.Empty;
            }
        }

        return string.Format("{0}/_layouts/15/myCode/CustomAccessDenied.aspx", serverRelativeUrl);
    }
}

To learn more about the redirect module, Microsoft(link in the comments) has a nice Walkthrough on how to create and register a custom module.

3
  • Walkthrough Microsoft TechNet Jun 9, 2016 at 4:22
  • Were you able to implement the custom pages? Jun 22, 2016 at 0:27
  • Didn't try this one, as I don't have farm administrator account. But thanks for your answer @Murilo Santana Oct 5, 2016 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.