UPDATE:
If you are running ASP.NET, you want to install NWebsec. It will allow you to configure HSTS but also Content-Security-Policy and other headers related to OWASP Secure Headers Project.
This solution was covered by Scott Hanselman in his blog (source at the bottom of the answer).
Basically, HSTS is just an HTTP header. But you only want to send it when you are in HTTPS. This will then lock your site in HTTPS for the max-age specified.
Here's what should be in the web.config of your application:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<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" url="https://{HTTP_HOST}/{R:1}"
redirectType="Permanent" />
</rule>
</rules>
<outboundRules>
<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
<match serverVariable="RESPONSE_Strict_Transport_Security"
pattern=".*" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action type="Rewrite" value="max-age=31536000" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
Source
<outboundRules>to test that evenRedirectnot works). Which other configurations of IIS could prevent the usage of<rewrite>part not working? SSL is installed and https://ok01.no-ip.org/ works inclusive support of HTTP/2 with rating A at https://www.ssllabs.com/ssltest/. It I include HSTS via<customHeaders>I get the rating A+, but HTTP has unneeded HSTS header. – Oleg Apr 05 '16 at 10:02%windir%\system32\inetsrv\rewrite.dllreally was not in the Module list. I registered it using "Configure Native Module" in IIS Manager and everything work now. I tried before many different ways. The usage of IIS Manager was of case the first one. I could see that it created the same sections inweb.configwhich you, Scott Hanselman and Doug Wilson described here. Thanks you anyway. – Oleg Apr 05 '16 at 12:25web.config, but nothing worked. I suppose that theapplicationHost.configwas reset by some repairing. The only real problem was that the "Web Platform Installer" don't provide repair package functionality. Probably I had to go in the list of installed software and to repair "IIS URL Rewrite Module 2". I just thought too long time, that I create wrong rule instead of trying to uninstall and install the Module. – Oleg Apr 05 '16 at 13:50