配置Https 和 HSTS
1. 视频 https://www.bilibili.com/video/av33344382/?p=2
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using System; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; namespace BlogDemo.Api { public class StartupProduction { public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddHttpsRedirection(options => { options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect; options.HttpsPort = 5001; }); services.AddHsts(options => { options.Preload = true; options.IncludeSubDomains = true; options.MaxAge = TimeSpan.FromDays(60); options.ExcludedHosts.Add("example.com"); options.ExcludedHosts.Add("www.example.com"); }); } public void Configure(IApplicationBuilder app) { app.UseHsts(); app.UseHttpsRedirection(); app.UseMvc(); } } }