How To - Add Custom Response Headers (Manipule web.config for cases like CORS)


Within OutSystems Cloud, unfortunately, isn't possible to access the IIS directly. Even when you need to change some simple configurations, like adding a specific header to the web.config file or increase the IIS limits to upload files. However, using a powerful tool available for everyone within forge (Factory Configuration) we are allowed to manipulate and include that so much required headers in the web file config.


This example is for CORS headers, please check the step-by-step guide below.


Note: This post is based on the already created article (https://www.outsystems.com/forums/discussion/16964/how-to-add-custom-response-headers/), nevertheless, I'm creating this one to remove the references to IIS and to add a more understandable step-by-step because people have shared that the first steps of the guide were confusing.


---



1 - Download and Install on your environment the Forge component "Factory Configuration" (https://www.outsystems.com/forge/component-overview/25/factory-configuration)


2 - Open the page http://<Environment_URL>/FactoryConfiguration in a browser and log in using Service Center Credentials.


3 - Click on "Shared Configuration" > "Create New Shared Configuration"


4 - Add a meaningful "Name" to the configuration and add the XSLT template to the "Value" input by clicking the button "FILL"


5 - Look for and replace the two following lines:

<xsl:attribute name="executionTimeout">180</xsl:attribute>
<xsl:attribute name="maxRequestLength">65536</xsl:attribute>

with:

<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="*" />


afterward, search for the following line:

<xsl:template match="/configuration/system.web/httpRuntime">

and replace with:

<xsl:template match="/configuration/system.webServer/httpProtocol/customHeaders">


6 - Click on tab "eSpaces" > search for the module that you want to change the headers > check the modules you want to add the configuration and click "Associate Shared Configuration"

7 - After finishing the steps above, don't forget to REPUBLISH your module.

8 - After republishing the module you should be able to see the headers within the requests of that module pages or services.


---


Hope this helps our community developments!

Kind Regards.


Yes I did all the steps and it does not work.