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