301 redirect from http to https with web.config

If you want to apply 301 Permanent Redirect for all your http requests to https requests - You need to add the following section under the system.webserver section of your web.config file:
    <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}" />