Force redirect HTTP to HTTPS Asp.net and MVC

By adding the following URL Rewriting rule we can force the site from HTTP to HTTPS.

<system.webServer>
        <rewrite>
            <rules>
                <rule name="http to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>
</system.webServer>

Resources and References from:

  1. namecheap.com
  2. StackOverflow

Tags

http https