Search code examples
asp.nethttp-redirectiisurl-rewritingplesk

IIS URL HTTP to HTTPS redirect not working on ASP.Net application


I have an ASP.Net application being hosted on a webserver with Plesk installed.

The application is hosted on a sub-domain (webapp.website.com) and the link to login to the system is supplied through the main domain website, so I haven't noticed this up until now.

If you type in webapp.website.com or http://webapp.website.com the website will connect to an unsecured page with the following error:

Server Error 403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied.

If you manually type in https://webapp.website.com (which is what the link is setup to do) the app connects just fine and works as expected.

I have enabled Permanent Redirect to HTTPS in Plesk, and have manually written a redirect rule in IIS Manager, but for some reason it seems to be ignoring this rule because the server connection is failing in HTTP and displaying the Server Error page instead.

How can I resolve the redirect issue to either stop the error on HTTP, or for it to skip over and redirect to HTTPS?


Solution

  • I suspect there may be a problem with your rules, you can try the following rules:

          <rewrite>
                <rules>
                    <rule name="Test" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="OFF" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
                    </rule>
                </rules>
            </rewrite>
    

    This rule will redirect all http requests to https.