Public Documentation
The OutSystems Platform handles unforeseen or unhandled errors that might occur in applications and displays feedback pages to end-users. You can create your own custom HTTP 404 (Not Found) error pages in Service Studio and configure them for your reactive applications. This applies to both on-premise and cloud customers. The method described in the Customizing OutSystems Platform Pages for Unhandled Errors article is still valid for on-premise customers, although more prone to errors.
This will be the page that will be shown in your application when the user tries to access a page that does not exist. It is recommended to have your error page inside the application it was created for. In this case, our demo application is called MyStore and we will create an error page inside it.
- Add a new screen to that application. For this example, we named it “NotFound”, but you can call it as you want.
- Tweak it as you like.
- Publish it.
When modifying your custom error page, you can add buttons and links to other pages or screens in the same application or domain. However, if you need to add a link to an external web page, you will need to specify the attribute target
with the value _top
to prevent unexpected behaviors.
- Go to Forge and search for: Custom 404 Plugin.
- Install it in your factory.
- Reference it in your application.
- In the error page you create, edit the OnDestroy event and add a call to the action NotFoundOnDestroy. This step is very important as it cleans some internal configurations before navigating out of the NotFound page.
Now that you have an application that contains your custom error page, you need to create some redirect rules that make the OutSystems platform use it as the default error page of your applications. You will add these redirect rules to a shared configuration file and then associate it to your application. You can create as many shared configurations as needed.
For that you need to go to Forge and install the module “Factory Configuration” into your factory.
- In the Factory Configuration app, go to Shared Configurations.
- Create a new Shared Configuration.
- In Pre-made Samples select “Custom Handler (.NET)”.
- Click on the “Fill” button.
- Give it a name.
Now you will have to modify its content so that it points to the custom 404 error page you just created. In our example, that screen is called “NotFound” and it is inside the same application we are tweaking, which is called “MyStore”. Please replace MyStore and NotFound by the name of your application and error page respectively.
Modify the value field, in the “httpErrors” section. It has to contain these three snippets: First one:
<!-- Define new Error page redirect string -->
<xsl:param name="new404" select="'..'/Custom404Plugin/NotFound.aspx?app=MyStore&page=NotFound'"/>
Second one:
<error statusCode="404" path="/Custom404Plugin/NotFound.aspx?app=MyStore&page=NotFound" subStatusCode="0" responseMode="ExecuteURL"/>
Third one:
<!-- Change 404 redirect -->
<xsl:template match="/configuration/system.web/customErrors/error/@redirect">
<xsl:attribute name="redirect">
<xsl:value-of select="$new404"/>
</xsl:attribute>
</xsl:template>
Click on “Save”.
Check this file for an example configuration.
You can have as many configurations as you want. Usually it will be one per application.
Now that your configuration is ready, you need to specify which applications it will apply to.
- In Factory Configuration, go to eSpaces.
- Search for the application you want to apply the configuration to.
- Select it in the list.
- Choose your shared configuration in the dropdown menu.
- Click on the “Associate Shared Configuration” button.
- Repeat the process for all the applications you want to add a custom error page to.
- Republish all the modified applications in Service Studio. If you want to define a custom error page for another application, you can follow the same steps and apply the configuration only for that application.
It might happen for a user to mistype the name of a specific application, for example typing https://mysite.something/MyStoree
instead of https://mysite.something/MyStore
. In that case, the error page associated with MyStore won’t be opened, as the user failed to access that specific module.
In order to address that situation, you need to define which application will be automatically opened when accessing your domain, and create a custom error page for it. This can be a blank application, or a real application with functionality. You can do that by configuring a site rule:
- Go to Service Center / Administration / SEO URLs / Site Rules.
- Click on New Site Rule.
- Write the domain of your OutSystems’ Platform in “Base URL”.
- Select your application in “Root Application”.
- Click on “Create”.
- Configure a custom 404 error page for it by following the steps explained before.
- Official documentation can be found at this location.
Please note that modifying the XML is an error-prone operation. In case the XML modified in the previous step is invalid, Service Studio will show a warning message when republishing the modified application, saying that the config was invalid and will be disregarded. In that case, please review your configuration file.
Look for the following common mistakes:
<!-- Define new Error page redirect string -->
<xsl:param name="new404" select="'/Custom404Plugin/NotFound.aspx?app=MyStore&page=NotFound'"/>
Make sure the URL defined for the variable “new404” is between single quotes and double quotes simultaneously.
<error statusCode="404" path="/Custom404Plugin/NotFound.aspx?app=MyStore&page=NotFound" subStatusCode="0" responseMode="ExecuteURL"/>
Make sure to correctly type the URL, including:
- your application name,
- your not-found page name,
- forward slashes,
- question mark,
- and escaping the ampersand