请问IIS如何启用HSTS(HTTP Strict Transport Security),让浏览器默认以https访问?
HSTS的效果是这样的:比如在浏览器地址栏输入 q.cnblogs.com (或 http://q.cnblogs.com ),浏览器会自己进行一个307重定向,以 https://q.cnblogs.com 访问,避免向服务器发送http请求。
参考资料:Understanding HTTP Strict Transport Security (HSTS) and preloading it into the browser
如果https与http绑定在不同的IIS站点上,直接在https站点的web.config中添加如下配置:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000" />
</customHeaders>
</httpProtocol>
</system.webServer>
如果在同一个IIS站点,需要针对https响应添加如下的url重写规则(详见How to enable HTTP Strict Transport Security (HSTS) in IIS7+):
<system.webServer>
<rewrite>
<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>
set http headers:Strict-Transport-Security
http://www.tuicool.com/articles/iMRjime 看看这个
http应该是存在,你跳到https上面啊,在golbal文件里面处理。
nopcomperce里面就有这样的处理,可以参考。