I’m trying to figure out why a site isn’t being redirected to HTTPS - I’ve got this in the StartUp.cs file (before the call to app.UseUmbraco()):
app.UseHttpsRedirection();
var rewriteOptions = new RewriteOptions()
.AddRedirectToNonWwwPermanent();
app.UseRewriter(rewriteOptions);
When requesting the site with HTTP only there is no redirect happening.
I’ve also tried having the .UseHttpsRedirection() call after the .UseRewriter() call (no luck).
The WWW redirect does seem to work (requesting the domain with www responds with a 308 redirect to the non-www host).
I can’t seem to find a definitive answer as to how this should work - even the Umbraco docs seem to not really know what to tell me. On the one side it says it’s as easy as adding the .UseHttpsRedirection() call before the call to .UseUmbraco(), but immediately thereafter it says to handle the redirection with IIS rewrites in Web.config (source: HTTPS | Umbraco CMS).
Thanks Jesper - no I haven’t tried that (it’s absolutely impossible for me to figure out which is the “preferred” way to do this - so many different versions on StackOverflow, the .NET docs etc. - the one I chose was one that worked for someone else ¯\(ツ)/¯ …)
I ended up using my own “preferred” version, i.e. adding a couple of rules to Web.config
If you are using IIS then web.config rewrite rules are actually preferred over the .NET middleware way. As it means the work is being done earlier in the request pipeline
Middleware wins out in that it can work cross platform.