I'm trying to create a custom 401 error page for my site. The setup is a SharePoint 2010 enterprise site with subwebs. The entire solution requires authentication (no anonymous access). I've tried both of these:
- Gets me very close, but I'm unable to redirect to my own custom html page. I can modify the default 401 page though.
- Doesn't really explain how to do it with an authenticated site as it requires access to the _layouts folder.
I've updated my web config like this:
<!-- inside <system.web> --> <customErrors defaultRedirect="404.htm" mode="On"> <error redirect="401-c.htm" statusCode="401" /> <error redirect="403.htm" statusCode="403" /> <error redirect="404.htm" statusCode="404" /> <error redirect="500.htm" statusCode="500" /> </customErrors> <!--inside <system.webServer> --> <httpErrors errorMode="Custom" existingResponse="Auto"/>
This setup allows me to redirect to the default 401.htm page (found in inetpub/custerr/), but I'm unable to redirect it. Even with the xml above (401-c.htm is found in the same directory) it only directs me to the default 401 page.
I don't have a clue what's going on here. Can anyone help?
Edit: An alternative web.config setup I've tried that also did not work:
<!-- inside <system.web> --> <customErrors mode="On"/> <!-- inside <system.webServer> --> <httpErrors errorMode="Custom" existingResponse="Auto"> <remove statusCode="401" subStatusCode="-1" /> <error statusCode="401" prefixLanguageFilePath="" path="/Pages/AccessDenied.aspx" responseMode="ExecuteURL" /> </httpErrors>
The system kept asking me for credentials even though I entered them correctly. When I closed the login box it did not give me my custom error page. Only a blank page with absolutely no content.
Edit2: I've concluded that none of the above solutions actually work as they intercept the 401 error BEFORE it reaches SharePoint. I need a solution like the one @GavinB and @Amit Kumawat suggests though for some reason this does not work either. It seems I need a way to rewrite the actual data that SharePoint sends back with the 401 error. I've tried this: http://www.sharepointblues.com/2010/02/12/custom-error-page-adapter/ but cannot seem to find the correct assembly for the "controlType" attribute.