Sharepoint 2010 Error Page Customization

Planning for Monitoring SharePoint 2010 is a key component of any enterprise installation. Micorosoft’s free (but unsupported and no longer available as an official download 🙂 ULS Viewer is an amazing tool to provide insights into the inner workings of the platform. However it can be difficult to distinguish which errors are actually show stoppers that are presented to your users and which are less visible “behind the scenes” issues.

One approach to get better insight into the most visible errors is to customize the standard Error.aspx page in the layouts and have it write to the Event Log whenever it is rendered. Editing files in the _layouts folder is officially unsupported by Microsoft and you can Modifying SharePoint Application Pages in the Right Way as time permits. Alternatively, you could add the following codes directly to the Error.aspx with the caveat you may need to do this again if a service pack or other official update overwrites your changes.

   string user = "none";
   if (Microsoft.SharePoint.SPContext.Current.Web.CurrentUser != null)
      user = Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.LoginName;
         System.Diagnostics.EventLog Log = new System.Diagnostics.EventLog();
         Log.Source = "SharePointUser";
         Log.WriteEntry("An unexpected error has stopped a page from rendering. Current user: " + user + " page: " + Request.ServerVariables["Server_Name"] + (Request.ServerVariables["Script_Name"] ?? "") + " " + RequestGuidText.Text, System.Diagnostics.EventLogEntryType.Error);
   //ignore logging errors

Now you can use your standard Windows Event Log tools to understand when users are actually presented with an Error screen that stops their processing. You could also adapt the approach to send an email notice instead. Either way you will now know which of the events in the ULS are presented to users and can use the correlation id to dig deeper.