HTTP到HTTPS重定向异常
问题描述:
我在我的MVC应用程序中使用HTTP到HTTPS重定向。HTTP到HTTPS重定向异常
这是我使用Web.config中的代码:
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
有一个在我的应用程序的页面不会对HTTPS工作,所以我需要一个例外添加到该规则。
我想知道是否有人可以帮助我,或给我看一些教程/例子。
答
你只需要添加另一个条件,否定您的网址的规则。你的新规则是这样的:
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{R:1}" pattern="myfolder\/myfile\.aspx" negate="true"/>
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
谢谢。它解决了我的问题。 – user3853986 2014-09-26 00:00:16