【发布时间】:2018-01-10 07:10:52
【问题描述】:
我有一个 .NET MVC 5 网站,我目前在生产环境中使用 Web 配置强制使用 https 并将 www 更改为非 www(具有有效证书)。这工作正常。我也有两个开发环境。这些环境设置了自签名证书,我想在这些环境中强制使用 https 并将 www 更改为非 www。
<rewrite>
<rules>
<rule name="Redirect any HTTP request to HTTPS with no www" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*"></match>
<conditions >
<add input="{HTTP_HOST}" pattern="^(.*)?website.com$"></add>
<add input="{HTTPS}" pattern="off"></add>
</conditions>
<action type="Redirect" url="https://website.com/{R:0}" redirectType="Permanent" appendQueryString="true"></action>
</rule>
<rule name="Redirect https www to HTTPS with no www" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*"></match>
<conditions >
<add input="{HTTP_HOST}" pattern="^www.website.com$"></add>
<add input="{HTTPS}" pattern="on"></add>
</conditions>
<action type="Redirect" url="https://website.com/{R:0}" redirectType="Permanent" appendQueryString="true"></action>
</rule>
</rules>
</rewrite>
但是,我当前的实现检查“HTTPS”= off/on,这在我的开发环境中总是“关闭”,因为它们没有有效的证书。这会导致无限重定向循环(Chrome 中的 TOO_MANY_REDIRECTS 错误)。我已经尝试了所有可以检查的宏({URL}、{REQUEST_URL}、{HTTP_HOST} 等),但这些都不是完全限定的 URL(即:“http://website.dev/whatever”) .如果我有这个,我可以检查是否有人尝试来使用 https 或 http。
这没什么大不了的,但是我已经花了太多时间了,哈哈!任何想法表示赞赏!
【问题讨论】:
标签: c# asp.net-mvc ssl iis