Custom HTML error pages - General Discussions - General Discussions - Progress Community
 General Discussions

Custom HTML error pages

  • Custom HTML error pages
  • Is there any objection to use IIS/ASP.NET approach to build custom error pages in pure HTML instead of the content pages hosted by Sitefinity itself ? This way we can get correct HTTP error codes returned without additional coding and make error pages available even if Sitefinity is not working. 

    My configuration (for a 404 error page) looks like this and works correctly. Just wondering if there any side effect not using Sitefinity-hosted  pages ?

        <customErrors mode="On">
          <error statusCode="404" redirect="~/Errors/404.html" />
        </customErrors>

        <httpErrors errorMode="Custom">
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" path="Errors\404.html" responseMode="File" />
        </httpErrors>

  • Hello,

    There is no impact if not using Sitefinity pages, Sitefinity is asp.net application and you are using the Asp.net built in functionality while Sitefinity is not active which is perfectly fine.

    I usually do custom errors like below, however use any method that you find more suitable.
    <httpErrors errorMode="Custom">
          <remove statusCode="404"/>
          <error statusCode="404" prefixLanguageFilePath=""  path="HtmlPage.html" responseMode="Redirect"/>
        </httpErrors>
     
      </system.webServer>

    Regards,
    Stanislav Velikov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • With the Redirect I will get 302 error code, not 404, right ?
  • OK, I meant 301. In other words if I use responseMode="Redirect"  the return code will be 301, not 404. In my opinion a site  should always return 404 code when requested resource is not found. With responseMode="File" I can achieve it via server-side redirect, right ?
  • Hi,

    301 is a redirect, 302 is another type of redirect, handle all types of redirect if needed, however for 301 make sure to have an entry.

    Regards,
    Stanislav Velikov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Personally, I prefer to use the IIS rewrite module for handling 301 and 302 redirects, as I find it more flexible and powerful.
  •  Stanislav, 

    My goal is to return 404 HTTP error code when page is not found. With responseMode="Redirect" I'll get 301, not 404.  Only with  responseMode="File" I can get the 404 code, right ?

  • Hi,

    @ Leonidius Here I am not sure I understand "With responseMode="File" I can achieve it via server-side redirect, right ?" Please elaborate on this.

    When the responceMode is set to file the server returns an html file for error page, more info on all responceModes here.

    When configuring httpErrors to handle 404 status codes every time a request to Url return 404 the httpErrors config will get you to redirect from the 404 error page to the predefined error page that the user should get.
    <httpErrors errorMode="Custom">
          <remove statusCode="404"/>
          <error statusCode="404" prefixLanguageFilePath=""  path="HtmlPage.html" responseMode="Redirect"/>
        </httpErrors>
      
      </system.webServer>

    Regards,
    Stanislav Velikov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Hello,

    Yes with responseMode="File" upon encountering an error the opened page for error will be returned with status 404. Note the file needs to be .html file to get rendered.
    <httpErrors errorMode="Custom">
          <remove statusCode="404"/>
          <error statusCode="404" prefixLanguageFilePath=""  path="HtmlPage1.html" responseMode="File"/>
        </httpErrors>

    Regards,
    Stanislav Velikov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • If anyone else is looking for a solution to this, check out the custom error page module I put on GitHub.

     I uploaded a short demo video to YouTube so you can see how it works.