MVC RequireHttps整个网站 [英] MVC RequireHttps entire site
问题描述
我已阅读有关使用RequireHttpsAttribute,以确保各个控制器的previous帖子:
I have read the previous posts about using the RequireHttpsAttribute to secure individual controllers:
<一个href=\"http://stackoverflow.com/questions/1639707/asp-net-mvc-requirehttps-in-production-only\">http://stackoverflow.com/questions/1639707/asp-net-mvc-requirehttps-in-production-only
但有这个适用于整个网站的方法吗?由于我的主机(discountasp.net)我不能用RequireSSL IIS设置。
but is there a way to apply this to the entire site? Due to my host (discountasp.net) I cannot use the "RequireSSL IIS" setting.
推荐答案
我结束了使用IIS的 URL重写2.0 ,以迫使该网站切换到HTTPS。在web.config中这code的伎俩:
I ended up using IIS URL Rewrite 2.0 to force the site to switch to HTTPS. This code in web.config does the trick:
<system.webServer>
<!-- This uses URL Rewrite 2.0 to force the entire site into SSL mode -->
<rewrite xdt:Transform="Insert">
<rules>
<rule name="Force HTTPS" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
这篇关于MVC RequireHttps整个网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!