Automatic redirection of HTTP to HTTPS Settings


Url Rewriting module of IIS to redirect to secure url

IIS 7 web.config should have this tag 
<system.webServer>
<rewrite>
    <rules>
        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
          <match url="(.*)" />
            <conditions>
              <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            </conditions>
          <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
    </rules>
    </rewrite>
</system.webServer>
IIS 8.x may be different

If you are using the MVC application then just by adding the filter you can acheive this.
filters.Add(new RequireHttpsAttribute());

If at all for some reason you dont want to do it in the server level and application level then you can do it in the controller level too.
Just decorate the controller with the attribute [RequireHttps] and we are good to go.

Comments

Popular posts from this blog

Error : ID4243: Could not create a SecurityToken.

MVC - Looping through the model properties from cshtml