Asp.net-Mvc

IIS 上從 http 到 https 的 URL 重寫不起作用,

  • January 5, 2021

我有個問題。在IIS我得到一個有兩個埠80443(https). 我想將http使用者的所有請求重定向到https. 我還添加了Rewrite rule to https,但是當我在瀏覽器中輸入時,http://localhost/site它給了我相同的頁面。我需要將使用者重定向到httpS://localhost/site.

也許這是因為我的本地配置?

我禁用Require SSLIIS.

The rule is:
<rewrite>
 <rules>
   <rule name="HTTPS Redirect">
     <match url="(.*)" ignoreCase="false" />
     <conditions>
       <add input="{HTTPS}" pattern="off" ignoreCase="false" />
     </conditions>
     <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
   </rule>
 </rules>
</rewrite>

謝謝你。

以下是我們在生產 IIS 7 站點上使用的將所有請求從 HTTP 重定向到 HTTPS 的確切規則

<configuration>
 <system.webServer>
   <rewrite>
     <rules>
       <rule name="Redirect to HTTPS" stopProcessing="true">
         <match url="(.*)" />
         <conditions>
           <add input="{HTTPS}" pattern="^OFF$" />
         </conditions>
         <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
       </rule>
     </rules>
   </rewrite>
 </system.webServer>
</configuration>

您發布的內容與我們使用的內容之間存在一些細微差別。此外,由於您在本地主機上執行,您不會使用帶有 Visual Studio 的內置 Web 伺服器嗎?我認為它不會處理 IIS 重寫規則。

引用自:https://stackoverflow.com/questions/13028223