Uploading large files is a constant headache for developers. Whenever you want to upload "larger" files on any ASP .NET website, you must edit the web.config file and that also applies to OutSytems.


On this POST, you will find how to upload big files within an OutSytems application using Factory Configuration to change the web.config. 

There are many settings that you might want to update when uploading large files e.g. session, request timeouts etc. In this post I will only address the following web.config attributes:


/configuration/system.web/httpRuntime/@maxRequestLength

/configuration/system.web/httpRuntime/@executionTimeout

/system.webServer/security/requestFiltering/requestLimits/@maxAllowedContentLength


But the same steps can be used to update other elements/attributes in the web.config file.

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


2 - Open the page http://<Enfironment_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.


5 - XSLT Template, on this example I'm using the following values:

- maxRequestLength (in KB) - 122880                               = 120 MB
- executionTimeout (in seconds) - 900                                = 15 minutes
- maxAllowedContentLength (in bytes) - 125829120          = 120 MB


(this values will need to be changed through the template in order to set the limits you pretend)


<?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"/>

  <!-- 
      Description
      This xslt is used to add uploading of large files capabilities to a outsystems eSpace on IIS.
      - It will upsert the attribute system.web/httpRuntime/@maxRequestLength (<=IIS6).
      - It will upsert the attribute system.webServer/security/requestFiltering/requestLimits/@maxAllowedContentLength (>=IIS7).
  -->

  <!-- Just copy all other xml parts, that don't have a specific template match. -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="configuration">
<!-- Create an "configuration" element in the output document. -->
<configuration>
    
    <!-- Copy child elements to output document. -->
    <xsl:apply-templates select="@*|node()"/>

    <!-- If the element "system.web" does not exist, create it in the output document. -->
    <xsl:if test="count(system.web) = 0">
      <system.web>
        <httpRuntime maxRequestLength="122880"  executionTimeout="900" />
      </system.web>
    </xsl:if>   

    <!-- If the element "system.webServer" does not exist, create it in the output document. -->
    <xsl:if test="count(system.webServer) = 0">
    <system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="125829120"/>
            </requestFiltering>
        </security>
    </system.webServer>
    </xsl:if>
</configuration>
  </xsl:template>

  <!-- If the element "system.web/httpRuntime" does not exist, add it. -->
  <xsl:template match="system.web[not(httpRuntime)]">
    <system.web>
      <xsl:apply-templates select="@*|node()"/>
      <httpRuntime maxRequestLength="122880" executionTimeout="900" />
    </system.web>
  </xsl:template>

  <!-- If the attribute "system.web/httpRuntime/@maxRequestLength" does not exist, add it. -->
  <xsl:template match="system.web/httpRuntime[not(@maxRequestLength)]">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:attribute name="maxRequestLength">
        <xsl:value-of select="'122880'"/>
      </xsl:attribute>
     <xsl:attribute name="executionTimeout">
      <xsl:value-of select="'900'"/>
    </xsl:attribute>
    </xsl:copy>
  </xsl:template>
  
  <!-- If the attribute "system.web/httpRuntime/@maxRequestLength" exists update it. -->
  <xsl:template match="system.web/httpRuntime/@maxRequestLength">
    <xsl:attribute name="maxRequestLength">
      <xsl:value-of select="'122880'"/>
    </xsl:attribute>
   <xsl:attribute name="executionTimeout">
      <xsl:value-of select="'900'"/>
    </xsl:attribute>
  </xsl:template>

  <!-- If the element "system.webServer/security" does not exist, add it. -->
  <xsl:template match="system.webServer[not(security)]">
    <system.webServer>
      <xsl:apply-templates select="@*|node()"/>
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="125829120"/>
        </requestFiltering>
      </security>
    </system.webServer>
  </xsl:template>

  <!-- If the element "system.webServer/security/requestFiltering" does not exist, add it. -->
  <xsl:template match="system.webServer/security[not(requestFiltering)]">
    <security>
      <xsl:apply-templates select="@*|node()"/>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="125829120"/>
        </requestFiltering>
    </security>
  </xsl:template>

  <!-- If the element "system.webServer/security/requestFiltering/requestLimits" does not exist, add it. -->
  <xsl:template match="system.webServer/security/requestFiltering[not(requestLimits)]">
    <requestFiltering>
      <xsl:apply-templates select="@*|node()"/>
        <requestLimits maxAllowedContentLength="125829120"/>
    </requestFiltering>
  </xsl:template>

  <!-- If the attribute "system.webServer/security/requestFiltering/requestLimits/@maxAllowedContentLength" does not exist, add it. -->
  <xsl:template match="system.webServer/security/requestFiltering/requestLimits[not(@maxAllowedContentLength)]">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:attribute name="maxAllowedContentLength">
        <xsl:value-of select="'125829120'"/>
      </xsl:attribute>
    </xsl:copy>
  </xsl:template>

  <!-- If the attribute "system.webServer/security/requestFiltering/requestLimits/@maxAllowedContentLength" exists update it. -->
  <xsl:template match="system.webServer/security/requestFiltering/requestLimits/@maxAllowedContentLength">
    <xsl:attribute name="maxAllowedContentLength">
      <xsl:value-of select="'125829120'"/>
    </xsl:attribute>
  </xsl:template>

</xsl:stylesheet>


6 - Then click on tab "eSpaces" > search for your module that you want to change the limits > and finally click "Associate Shared Configuration"



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


Hope this helps our community developments!

Kind Regards.

Thank you for a very informative post !

Hi João,

Do you know if it's possible to configure that for a specific page or part of your app instead of the whole environment.

Regards,

Marcelo

Marcelo Ferreira wrote:

Hi João,

Do you know if it's possible to configure that for a specific page or part of your app instead of the whole environment.

Regards,

Marcelo

Hello Marcelo,


The configuration above will be applied for each module you associate (step 6), not directly to all environment or only to a page.


Kind Regards.

Hi,

Thx for the quick answer. Really nice post.

Regards,

Marcelo