Redirect Http to Https on IIS

Asked

Viewed 519 times

1

I’m setting up a server IIS to run an application asp.net core 1.0 but the application is https and by typing www.dominio.com.br it does not redirect to the https, I have already made the following settings:

<!--<rewrite>
  <rules>
    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
  </rules>
</rewrite>

and in the Startup.cs I put the following code inside the method Configure:

app.Use(async (httpContext, next) =>
        {
            var url = httpContext.Request.GetDisplayUrl();
            if (!url.StartsWith("https"))
            {

                    httpContext.Response.Redirect("https://www.dominio.com.br" + (httpContext.Request.Path.HasValue ? httpContext.Request.Path.Value : string.Empty), true);                    
                return;
            }
            await next();
        });

Still no one’s solved it, does anyone have any idea how I can do it?

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.