How to display Custom Error Page

Most of the time we don’t want to display WSS default Error Page, as it looks scary. Instead we want to display our custom error page. Displaying custom error page when exception occurs provide lots of benefits like we can create error log for further debugging. Process of displaying custom error page is very simple and involve following steps:
  1. Backup the web.config.
  2. Open the web.config in notepad and change ( for Sharepoint, if you are not doing it for Sharepoint then skip this step)
    <SafeMode MaxControls="200" CallStack="false"
    to
    <SafeMode MaxControls="200" CallStack="true"

  3. You will also need to change the CustomErrors mode to "Off"
    <customErrors mode="Off"/>
  4. Save changes.
  5. Backup the Global.asax.
  6. Open the Global.asax in notepad or any Editor and insert this code
<script runat="server">
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Response.Redirect("<Url of Custom Error Page>");
}
</script>

  1. Save changes.

WSS Utility to Transfer Control(Redirect) to WSS default Error Page

If you want to display WSS default error page from your custom code then there is a function available in SPUtility class. You can call this funtion and pass message to be displayed as an argument.

// Transfer to error Page
SPUtility.TransferToErrorPage(string Message)

For more information about go to MSDN

Comments

Popular posts from this blog

Installation and Configuration of Office Online Server with SharePoint 2019

Workflow Manager 1.0- Installation, Configuration and Issues

SharePoint 2019 Upgrade Part 6: SharePoint Upgrade Issues