Search code examples
htmlcssasp.netweb-config

Web.Config redirect to maintenance page?


From https://gist.github.com/stevensk/c8108311b82ba1591cb1be018bbe0119, I have added the code below to our web.config for "site maintenance page redirect".

For an IP that isn't mine (mine is 3rd item down in IP list), the user is directed to the site maintenance page, but it hasn't been displaying the background image, specified fonts, or other CSS file styles.

The Firefox inspector shows the following message in red:

The resource from
“https://www.example.com/pages/maintenance/message/default.htm”
was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).

How can I get the maintenance page to have the correct fonts, images and other styles applied?

<rewrite>

            <!-- Maintenance rewrite map
             - Add allowed IP addresses to grant access during maintenance period
             - To activate, uncomment Maintenance Redirect rule
             - And replace last key with current IP found at /pages/test/remote-name/
             -->
            
            <rewriteMaps>
                <rewriteMap name="MaintenanceIpAddressWhitelist" defaultValue="">                   
                    <add key="192.168.0.1" value="1" />
                    <add key="127.0.0.1" value="1" />
                    <add key="198.43.70.125" value="1"/>
                </rewriteMap>
            </rewriteMaps>          
            
            <rules>             
                
                <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
                </rule>

                <rule name="ensurewww" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
                    </conditions>
                    <action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" />
                </rule>

                <!-- Maintenance Rule -->
                <rule name="Maintenance Redirect">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{MaintenanceIpAddressWhitelist:{REMOTE_ADDR}}" matchType="Pattern" pattern="1" negate="true" />
                        <add input="{REQUEST_URI}" pattern="^/pages/maintenance/message/default.htm$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="/pages/maintenance/message/default.htm" appendQueryString="false" redirectType="Temporary"/>
                </rule>

            </rules>

        </rewrite>

Solution

  • I ended up embedding images, css, svg and font files as base64 into the default.htm page.