Login

Customized error handling

Versions: 4.20, FAQ number: 82, Old FAQ number: 1023

EPiServer has a built-in error handler that captures exceptions inside the ASP.NET application were EPiServer resides. A friendly error message is displayed instead of the yellow and red .NET error that most users do not understand. An optional e-mail report form is displayed if an e-mail address is set as specified below. Since the error handler is initialized after ASP.NET is started some configurations and dll problems are not handled.

Why not only use the ASP.NET settings for error pages?

The goal was to have out-of-the-box friendly localized error messages where the default exception information could be visible for special users but always included in an error report mail for simplified troubleshooting.

Enable and disable the error handler

The error handler is configured using two web.config settings, both settable from System Settings in admin mode.

Setting in web.config Values Description
EPsErrorHandling On/Off/RemoteOnly Enable or disable the error handler. By setting this value to RemoteOnly the error handler will only be activated for users not accessing this site from the local machine. Useful for debugging purposes.
EPsErrorMail <email> If you set a e-mail adress a error report form will be displayed on error pages, the e-mail will always contain the full exception information even though the user doesnt have access to see detailed error messages.

Configuration of detailed error messages

Even though the friendly error message is displayed you have an option to enable detailed exception information for some users or groups, displayed in a section below the friendly error message. By default Administrators have permissions to detailed exception information. Go to "Detailed error messages for troubleshooting" settings in admin mode under "Permissions to functions" on the menu to change this.

Adding descriptions for custom exceptions

You may add your own XML file in the lang directory to add custom descriptions for exceptions that otherwise would fallback on the default error message. Example below:

<exceptionmanager>
 <httperrors >
   <status code ="131">
      <title>Error message for HTTP 131</title >
      <description>Some description.</description >
   </status >
 </httperrors >
<exceptions >
<exception type ="development.MyCustomException">
  
<title>Error in my function</title >
  
<description>Error in my function, try again later</description >
 </exception >
</exceptions >
</exceptionmanager>

Customizing layout of .NET exceptions

You can not customize the layout of error messages with EPiServer's error handler at this point, as it has advanced functionality to incapsulate the .NET error message and error reporting. If you have special needs for error handling you have the option to disable the EPiServer error handler and use the default ASP.NET error handling instead.
To do this, turn off EPiServer's error handler in System settings in Admin mode, or just set EPsErrorHandling = "Off" in web.config. After that, just add your own error handler in Global.asax.cs:

public Global()
{
  InitializeComponent();

  Error += new EventHandler(CatchUnhandledException);
}
  
private void CatchUnhandledException(object sender,EventArgs evt)
{
  Exception e = Server.GetLastError();
  Response.Write("<h2>Unhandled exception caught:</h2>" +
                 e.InnerException.Message);
  Response.End();
}

For more information about the default error handler behavior in ASP.NET, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfCustomerrorsSection.asp.

Customizing IIS errors

Errors generated by IIS are configured in the Internet Information Services Manager. Currently EPiServer uses the 404 error to redirect invalid urls into EPiServer. You may change the default setting of URL /Util/NotFound.aspx under Custom Errors in IIS as long as it is another ASPX page, otherwise "Simple address to page" and virtual shares in the Unified file system will stop working. Make sure you send back a Response.Status = 404 from the code in your custom ASPX page, otherwise you may experience problems with Internet Explorer when it tries to load for example a missing image when you customize the HTML.

EPiTrace logger