Thursday, January 1, 2015

DNN Custom Error Pages

[Custom Errors] 

Default error pages may expose a lot of information, Like the language and the server you use, and such Info. could be used by malicious users to attack your site and your server.

Also default error pages look very ugly and outdated design, which may harm your brand.

So It's always recommended to use custom error pages..

So, How Could I display a custom error page in DNN when error occurs ?

To Disable DNN Error Handling, and Let Errors Bubble..
Host Settings >> Appearance >> Un-Check "Use Custom Error Messages? "


To Redirect Users To, Can be aspx page, but I prefer HTML
Then Create HTML Page at the root with Style


Then in Enable CustomErrors in Web.Config :
    <customErrors mode="On">
      <error statusCode="500" redirect="/MyCustomError.html"/>
      <error statusCode="404" redirect="/MyCustomError.html"/>
      <error statusCode="403" redirect="/MyCustomError.html"/>
    </customErrors>
  
Also You can Override IIS Error Pages and Redirect to your Custom Error Pages using the below web.config snippet

    <httpErrors>
      <remove statusCode="404" subStatusCode="-1"/>
      <error statusCode="404" prefixLanguageFilePath="" path="/MyCustomError.aspx" responseMode="ExecuteURL"/>
      <remove statusCode="403" subStatusCode="-1"/>
      <error statusCode="403" prefixLanguageFilePath="" path="/MyCustomError.html" responseMode="ExecuteURL"/>
    </httpErrors>