Search code examples
iis-7httpsasmx

How to Enforce HTTPS For ASMX Service


I have a number of existing ASMX web services running on IIS7, and want to change them so that all requests and responses must be made over HTTPS.

The site is also running other pages like PHP and Classic ASP, so I can't just change the site root to serve HTTPS pages.

How can I set this per ASMX serivce (application), so that if somebody visits http://www.mydomain.com/MyService/ServiceName.asmx it either redirects them to https://www.mydomain.com/MyService/ServiceName.asmx or returns a 404 error ?

Thoughts and best approach ?


Solution

  • Have you tried with URL rewrite?

    <rewrite>
        <rules>
            <rule name="Force HTTPS" stopProcessing="true">
                <match url="(.*)/ServiceName.asmx" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>