繁体   English   中英

IIS重写:HTTP到HTTPS,反之亦然,为什么不起作用

[英]IIS Rewrite: HTTP to HTTPS and vice versa, why doesn't it work

我有一个页面,除了两个页面之外,我必须将每个HTTP请求重定向到HTTPS请求,在这两个页面上,我必须做相反的事情,因为我们包括一个通过HTTP加载的远程第3方脚本。

由于这是开发环境(Visual Studio),因此HTTP端口为50382,HTTPS为44300。

这是到目前为止我所拥有的(CustomerPortal是其中的几页)。 它不起作用,每个对CustomerPortal的请求都在Chrome中显示为“已取消”。 我认为问题是HTTP到HTTPS规则,该规则不排除CustomerPortal.aspx,尽管我显然为这种情况添加了条件。

我不知道为什么它不起作用,我不是RegEx或IIS的专家,但对我来说规则看起来是正确的(显然不是)。

<rules>
    <clear />
    <rule name="HTTP to HTTPS on different SSL Port" enabled="true">
      <match url="^(.*\.aspx)$" ignoreCase="true" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
        <add input="{HTTPS}" pattern="off" />
        <add input="{HTTP_HOST}" pattern="([^/:]*?):[^/]*?" />
        <add input="{SERVER_PORT}" pattern="^50382$" />
        <add input="{URL}" negate="true" pattern="CustomerPortal\.aspx$" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="https://{C:1}:44300/{R:0}" appendQueryString="false" />
    </rule>

    <rule name="Redirect to http 2">
      <match url="CustomerPortal\.aspx$"/>
      <conditions>
        <add input="{SERVER_PORT}" pattern="^44300$" />
      </conditions>
      <action type="Redirect" url="http://{HTTP_HOST}:50382/Guest/Portal/CustomerPortal.aspx" redirectType="Found" appendQueryString="true"  />
    </rule>
  </rules>

好的,在进一步调试和测试后,我发现了问题。 规则本身很好。 问题是我如何从我的C#代码中调用Response.Redirect

这不行

Response.Redirect("~/Path/To/MyFile.aspx");

这确实

Response.Redirect("http://mypage.com/Path/To/MyFile.aspx");

我不知道为什么它不起作用。 但是,如果您在从HTTPS重定向到HTTP时使用绝对路径,反之亦然,则可以按预期工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM