簡體   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