1
votes

I'm trying to rewrite all my URL's to HTTPS but getting this error, not sure what am I doing wrong:

Config Error

This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".

web.config:

<rewrite>
      <allowedServerVariables>
        <add name="HTTPS" />
        <add name="X-FORWARDED-PROTO" />
      </allowedServerVariables>
      <rules>
        <rule name="HTTPS_AlwaysOn" patternSyntax="Wildcard">
          <match url="*" />
          <serverVariables>
            <set name="HTTPS" value="on" />
          </serverVariables>
          <action type="None" />
          <conditions>
            <add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" />
          </conditions>
        </rule>
      </rules>
    </rewrite>

I have also installed Rewrite module and ARR on Docker container

# Install Url Rewrite
ADD https://download.microsoft.com/download/1/2/8/128E2E22-C1B9-44A4-BE2A-5859ED1D4592/rewrite_amd64_en-US.msi /install/rewrite_amd64_en-US.msi
RUN msiexec.exe /i c:\install\rewrite_amd64_en-US.msi /passive

ADD  https://download.microsoft.com/download/A/D/C/ADC4BAF8-A094-47B5-A6F6-CE4C5ED18BF8/ARRv3_setup_amd64_en-us.EXE /install/ARRv3_setup_amd64_en-us.exe
RUN c:\install\ARRv3_setup_amd64_en-us.exe /Q
2
you could try this rule: <rule name="HTTPS force" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" /> </rule>Jalpa Panchal

2 Answers

0
votes

Build a normal IIS 10 machine for testing first and you should notice the same error, as that allowedServerVariables cannot be in web.config.

Reference

0
votes

To enable SSL Rewrite simply add this inside:

<rules>
  <rule name="SSL Redirect" enabled="true" stopProcessing="true">
    <match url="(.*)"/>
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTPS}" pattern="off"/>
        <add input="{HTTP_HOST}" pattern="localhost" negate="true"/>
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
  </rule>
</rules>