We use static html pages for the 500 errors to make sure that something renders assuming that the site is down.

The issue with this is that these static pages would have to be manually edited and pushed via code deployments for it to get updated on the CD servers.

I would like to have a content page for the 500 and on publish it would be great to auto-generate the 500 pages in a multi-site solution.

Does any one know how I could generate these files based on the app pool users security permission on the CD servers?


Akshay we do something similar to this (for a different use case to 500 errors) but instead of publishing out actual pages we instead write Json files out to the server which store the content for the page.

The content of these files are managed in Sitecore under a settings item and then on publish of the item the Json file is created (pre-fixed with the sitename) and saved to the /data folder on the server.

Example Code - reworked for your use-case

public class SaveJsonFileOnPublishOfSettings
  public void SaveJsonFile(object sender, EventArgs args)
      Item rootItem = SitecoreHelpers.GetRootItem(args);

      if (rootItem != null && rootItem.TemplateID.Guid == "settings-item-template-id")
        string content = rootItem.Fields["500-error-page-content-field-id"].Value;

        string siteName = SiteHelper.GetCurrentSiteName(rootItem.Paths.Path);
        JObject jsonFiveHundredError = JObject.FromObject(new JsonFiveHundredError() {Content = content});
        string dataFolder = Settings.DataFolder;
        File.WriteAllText(  string.Format(@"{0}\JsonContent\{1}_FiveHundredError.json", dataFolder, siteName), jsonFiveHundredError.ToString());
    catch (Exception ex)
      throw new ArgumentException(ex.ToString());

Example Patch file

      <event name="publish:end:remote">
        <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
          <sites hint="list">
            <site name="mysite">MySite</site>
        <handler type="MySitecore.Extensions.Pipelines.SaveJsonFileOnPublishOfSettings, MySitecore.Extensions" method="SaveJsonFile" />

You can then have a simple 500 error page that pulls in this json content and doesn't need to connect to database or Sitecore. You could also modify this to instead write out a static HTML file (perhaps based on a Razor template in your website code) which contains this content instead to avoid any code execution.

Hopefully this helps.

  • Thanks Adam. How do you manage the assets from the media library. Assuming that the site is down as in Sitecore is down, we cannot take any chances hitting the media library. – ASura Sep 20 '17 at 15:40
  • Also, your app pool user has write permissions inside the website folder ? – ASura Sep 20 '17 at 15:40
  • I don't think the app pool user has write permissions inside the website folder as we locate our /data folder outside of the main website folder (to aid deployments and for security). I terms of media I'd perhaps look at copying any media files over to the static JsonContent folder at publish time in the same way as the text is (add the media file names/paths as other fields in your json file) and then you can directly reference them without having to go via Sitecores media file handler. – Adam Seabridge Sep 20 '17 at 15:54
  • So the json gets written to the data folder? and the front end static html pulls the file from the data folder? I feel like I am missing something. – ASura Sep 22 '17 at 15:02
  • Yes the json gets written to the data folder and then in our case (as it's not a 500 page) we read the json file like so in an mvc page: JsonConvert.DeserializeObject<StaticHomepage>(System.IO.File.ReadAllText(filePath)); – Adam Seabridge Sep 22 '17 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.