IIS: Redirect HTTP to HTTPS

To cleanly redirect HTTP to HTTPS with IIS, first install the URL Rewrite module, and then add the following to your web.config. Also remember to have bindings defined for your site for both HTTPS(443) and HTTP(80).

        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
          <match url="(.*)" />
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />

Source: StackOverflow