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
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.
-
-
-
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