我尝试了几乎所有与web.config更改有关的建议,都将http重定向到https。Best way in asp.net to force https for an entire site?
但是它对我的ASP.net网站不起作用。我使用godaddy共享托管,帐户中有多个站点。我仅对一个网站启用了ssl,必须将其添加到过滤器中,以便同一帐户中的其他网站不会重定向到https。这是我的web.config:
<rewrite> <rules> <rule name="HTTP to HTTPS redirect" stopProcessing="true" enabled="true"> <match url="singledomain.*" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite>
我可以同时通过http和https访问该网站。但是它永远不会从http重定向到https。如果我的比赛条件正确,那是什么问题,可以帮忙吗?
谢谢。
在这里找到解决方案:https://stackoverflow.com/a/17066105/2535756在这里发布有效的代码:
<rewrite>
<rules>
<rule name="HTTP to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(singledomain.com.*)" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
根据GoDaddy的经验,Plesk应用程序中确实存在一个设置,该设置实际上将强制从HTTP重定向到HTTPS。您可以在IIS设置下的目录安全设置下找到此设置,并选中要求SSL / TSL框。这会强制用户的浏览器使用HTTPS而不是HTTP。