asp.net-mvc-3 - 如何使用 URL 重写规则过滤 URL

标签 asp.net-mvc-3 c#-4.0 ssl url-rewriting

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

我在我的 web.config 文件中使用了上面的 url 重写规则来为整个站点启用 SSL。 现在我需要更改上面的规则来过滤 2 个应该作为 http 工作的 url。 假设这些网址为 https://www.domain.com/owner/Marketinghttps://www.domain.com/owner/getinfo . 目前这些网址是 https,因此高于规则。那么我如何更改上述规则以过滤 2 个以上的网址(即 http://www.domain.com/owner/Marketinghttp://www.domain.com/owner/getinfo )?

最佳答案

我会添加一个单独的规则来排除不应重定向到 https 的 url。

我现在无法测试它,因为我手边没有 IIS7。但试一试:

<rewrite>
  <rules>
    <rule name="Skip HTTPs" enabled="true" stopProcessing="true">
      <match url="^(Marketing|getinfo)" ignoreCase="true" />
      <conditions>
        <add input="{HTTPS}" pattern="OFF" />
      </conditions>
      <action type="None" />
    </rule>
    <rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
      <match url="(.*)" ignoreCase="true" />
      <conditions>
        <add input="{HTTPS}" pattern="OFF" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
    </rule>
  </rules>
</rewrite>

请注意,您必须按照您的示例将该文件放入/owner/目录。

您可能已经看过相关文档 - 只需指出我在哪里找到它:

http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

这里还有一个使用前瞻性正则表达式规则可能重复的问题:Rewriting URLs in IIS7

关于asp.net-mvc-3 - 如何使用 URL 重写规则过滤 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21983780/

相关文章:

c# - 将 IronPython 代码编译为 EXE 或 DLL

c# - C# 4.0 的新功能 - "Optional Parameters"CLS 兼容吗?

Plesk 中域的默认 SSL 证书 > 11

sql-server - MVC 3 : The MSDTC transaction manager was unable to pull the transaction from the source

asp.net-mvc - asp.net mvc View 模型中的默认值

asp.net-mvc-3 - 企业中业务实体验证的首选方法

c# - 在 controller.OnActionExecuting 中设置结果后 ActionFilter 未触发

c# - SyncRoot 如何/为什么隐藏在 Queue<T> 上?

java - SSLEngine 关闭

php - 如何设置 OpenSSL 以便我可以使用 PHP vis Gmail SMTP 发送邮件?