Redirection from Http to Https works only internally on iis server browser where is app installed

1.4k Views Asked by At

Redirection from http to https not working properly, below is my code used in web.config file

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

I have a valid SSL certificate, and I disable Require SSL.

with this code in global.asax file

      protected void Application_BeginRequest()
    {
        if (!Request.IsSecureConnection)
        {
            Response.Redirect(Request.Url.AbsoluteUri.Replace("http://", "https://"));
        }
    }

I tried all argument but nothing works, redirection works only if I open the browser from the server it self.

1

There are 1 best solutions below

2
anand On

You could do the same from the IIS Manager:

Open IIS Manager -> Select your site from Connections Panel (in left side) -> Click on HSTS... option from Action Panel(in right side) -> Check the "Enable" Option and "Redirect Http to Https" -> Now click the "OK" button.

Hope it will work for you.