配置Https 和 HSTS
作者:互联网
1. 视频 https://www.bilibili.com/video/av33344382/?p=2
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(); } } }View Code
标签:AspNetCore,HSTS,app,配置,Microsoft,Https,services,using,options 来源: https://www.cnblogs.com/Ken-Cai/p/10344808.html