asp.net - 在与 IIS 8.5 (ASP.NET) 兼容的 WEB.CONFIG 中将 HTTP 重定向到 HTTPS

标签 asp.net https url-rewriting web-config iis-8.5

在这里发疯。我有一条规则,从 HTTP 重定向所有页面至HTTPS ,在 IIS8 中工作得很好但我在 IIS 8.5 中收到 500 内部服务器错误。我想我缺少一些配置,但是在搜索了几个小时并尝试了 system.WebServer 中重写规则的各种不同更改后不知所措在 web.config文件。
这是代码(大约 5 种变体之一 - 都不起作用)

<rewrite>
  <rules>
    <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
          <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

无需简单地将其写入 MasterPage (我可以这样做,但是这该死的东西在升级之前工作得很好),我有什么遗漏吗?也许是配置?

另一个有效的版本(在 IIS8.5 托管的另一个站点上)
<rewrite>
  <rules>
    <rule name="httpsredirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
  </rules>
</rewrite>

最佳答案

看起来你忘记安装 rewriteurl 模块了。在这里获取:

http://www.iis.net/downloads/microsoft/url-rewrite

关于asp.net - 在与 IIS 8.5 (ASP.NET) 兼容的 WEB.CONFIG 中将 HTTP 重定向到 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38178405/

相关文章:

Asp.net Webform 显示警报和重定向

javascript - 带有 javascript 文件的 html 图表

javascript - 如何使用 window.history.pushState

html - 页面 URL 可以与文件名不同吗?

php - 使用 PHP GET 方法时进行 URL 重写

c# - Oracle数据访问版本问题

asp.net - 使用 Javascript 更新客户端上的 TextBox 并从服务器读取值

laravel - 在 apache 服务器上为 laravel 配置 https

networking - Haskell 网络.浏览器 HTTPS 连接

asp.net-mvc-2 - 如何使用 SSL 页面创建 Cookie?