iis urlrewrite HTTPS,但服务(.asmx和.svc)或具有参数/值的特定服务除外

vlju58qv  于 2022-11-30  发布在  其他
关注(0)|答案(2)|浏览(107)

我希望我的网站默认为HTTPS,除了服务(.asmx和 .svc)在Http和Http中工作。
由于客户端是在jsp中开发的,并且使用http请求,因此一些REST服务将是http,一个客户端是Windows,它使用与https相同的服务。
我要跳过
**.asmx
.svc**或特定服务,以便任何客户端都可以在http或https中请求服务。
我使用下面的代码:

<rule name="Force HTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
       <!-- <add input="{HTTPS}" pattern="^OFF$" /> -->
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/myservice.svc$" ignoreCase="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/myservice.svc?(.*)" ignoreCase="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/restserv.svc$" ignoreCase="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/restserv.svc/(.*)" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

它们都不起作用:只有 /myservice.svc 在http中工作,但当用户点击参数**/myservice.svc?wsdl/myservice.svc/getdata/user-name**时,它会转发到https。restserv.svc也会发生同样的情况
如何跳过 *.svc或我的特定服务跳过参数?

oxf4rvwz

oxf4rvwz1#

您可以尝试以下规则:

<rule name="Https Except Service" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/(myservice\.svc.*)" ignoreCase="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/(restserv\.svc.*)" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

如果您仍然面临问题,请尝试在iis中运行失败请求跟踪:
使用失败请求跟踪来跟踪重写规则

wyyhbhjk

wyyhbhjk2#

这是我在asmx Web服务中使用的规则,允许使用“?wsdl”或类似的语句:

<rule name="WebSite HTTPS Redirect" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
        <add input="{REQUEST_URI}" pattern="\.asmx.*" negate="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>

相关问题