Startup.ConfigureServices

Add the following to the beginning of the Startup.ConfigureServices method:

services.AddMvc( options =>
{
    options.Filters.Add( new RequireHttpsAttribute() );
});

Note a new method is added to the filter collection.

Startup.Configure

Add the following to the beginning of the Startup.Configure method to:

app.UseRewriter(new RewriteOptions().AddRedirectToHttps(301, 44343));

The following using statement is required:

using Microsoft.AspNetCore.Rewrite;

This will force anyone using http to use https.

Copyright © 2024 delaney. All rights reserved.