Question

I'm deploying a web application as an Azure Cloud Service. The Cloud Service config specifies endpoints for both HTTP & HTTPS. All the relevant CSCFG & CSDEF Cert stuff is configured correctly and the cert deployed and this all works.

I'd now like to add a HTTP->HTTPS rewrite rule to force any calls to HTTP to get redirected to the secure site.

I have a web.production.config transform on my web.config which adds the following block. (Taken from http://blog.smarx.com/posts/redirecting-to-https-in-windows-azure-two-methods )

   <system.webServer>
    <rewrite xdt:Transform="Insert">
      <rules>
        <rule name="RedirectToHTTPS">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            <add input="{URL}" pattern="/$" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

This results in the following <system.webServer> section in the deployed config file.

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
      <add name="DotLess" preCondition="integratedMode" type="dotless.Core.LessCssHttpHandler,dotless.Core" path="*.LESS" verb="*" />
    </handlers>
    <rewrite>
      <rules>
        <rule name="RedirectToHTTPS">
          <match url="(.*)"/>
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
            <add input="{URL}" pattern="/$" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
          </conditions>
          <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther"/>
        </rule>
      </rules>
    </rewrite>

  </system.webServer>

When I launch the site and browse to any of the urls (http or https, cloudapp.net or customdomain), I get an 500.19 error.

From googling, this would seem to indicate that the URLRewrite module isn't turned on, but everything I've read says that it's on by default for Cloud Service Applications.

In addition, I've scoured the log files. I can see the 500 errors in the BLOB Storage, wad-iis-logfiles container. But can't find anything else in any of the event logs under table storage. The service is configured to be dumping the most verbose Application Event & Diagnostic logging information.

Is there anyway to figure out the exact error for the 500.19 page, or any pointers based on the above for what might be going wrong ?

Was it helpful?

Solution

I finally figured out the issue.

I was using an xdt:insert on the transform, and because of the build & deploy process, it was actually running the Transformation twice, resulting in 2 rewrite sections appearing in the deployed web.config.

The solution was to add an empty

<system.webServer>
   <rewrite />
</system.webServer>

To the template config file, and perform an xdt:Replace instead.

I was able to debug it by enabling the RDP settings on the publish deployment and then examing the Event Log, IIS Config & Web.Config on the actual instance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top