Search code examples
http-redirectiisasmx

how to write an iis config rule to stop redirect of .asmx


I have this section in my web config to redirect http requests to https excluding .asmx references

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

This redirects http requests OK but web services don't work - I get

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

with the error genereated at

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


Solution

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

    You want to stop redirect of .asmx, but in your rewrite rule, your parameter is .aspx, so you need to change the parameter to .asmx.

    Or you can also try the following rewrite rules:

    <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}" />