Customized settings in web.config files per eSpace using Factory Configuration

thumbs_up_ico2thumbs_down_ico0
Context:
  • You want to define custom settings in the web.config file that vary from application to application (e.g. you want custom error handlers for HTTP error codes, that vary for each eSpace);
  • You are running the OutSystems Platform 4.1 for .NET;

How to do it?

You could simply change the web.config after republishing the application, but that would not be very useful because web.config is rewritten everytime you publish a new eSpace version, so you would have to manually change the web.config everytime a new version of your application is deployed.

Using Factory Configuration

The right way to do it is by using the Service Center Factory Configuration (http://www.outsystems.com/NetworkSolutions/projectdetail.aspx?ProjectId=25). You will need to deploy this solution, and configure the settings for it.
This application uses XSLT to make changes to the default web.config file, so you will need some insight on how to write XSLT. You will also need to check the default web.config file - you can simply navigate to the Hub Server folder and copy the web.config that is deployed by default for that eSpace.

You can also use some of the predefined templates to have an idea of how things can be done.

Creating rules

After deploying Factory Configuration, simply access http://server/FactoryConfiguration, login (using Service Center credentials) and navigate to Shared Configurations. Here, you can create a new shared configuration, and either use one of the templates or create a configuration from scratch. After creating your XLST rule, you simply need to navigate to eSpace and associate your configuration(s) to the eSpace(s) you wish to see associated with them. Afterwards, you need to republish the eSpaces so the changes become effective.

Example

Below there is an example that redirects all requests to non-existent aspx pages to the Service Center Login page:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" encoding="UTF-8"/>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="/configuration/system.web/customErrors/error">
<xsl:copy>
<xsl:attribute name="statusCode">404</xsl:attribute>
<xsl:attribute name="redirect">/ServiceCenter/Login.aspx</xsl:attribute>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>