首页 > 解决方案 > 如何编写 iis 配置规则以停止 .asmx 的重定向

问题描述

我的 Web 配置中有此部分,用于将 http 请求重定向到 https,不包括 .asmx 引用

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

这可以重定向 http 请求,但 Web 服务不起作用 - 我明白了

<head><title>Document Moved</title></head>
 <body><h1>Object Moved</h1>This document may be found <a 
 HREF="https://v3.myurl.net/WSEntrant.asmx">here</a></body>

产生的错误是

System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at PCS_Spe

cification.wsEntrant.WSEntrant.refresh

标签: redirectiisasmx

解决方案


<add input="{URL}" pattern="^.aspx" ignoreCase="true" negate="true" />

您想停止 的重定向.asmx,但在您的重写规则中,您的参数是.aspx,因此您需要将参数更改为.asmx

或者您也可以尝试以下重写规则:

<rule name="RewriteAllButasmx" stopProcessing="true">
  <match url="(.*)" />
    <conditions>
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{URL}" negate="true" pattern="\.asmx$" />
    </conditions>
  <action type="Rewrite" url="https://{HTTP_HOST}/{R:1}" />

推荐阅读