码迷,mamicode.com
首页 > Web开发 > 详细

配置Https 和 HSTS

时间:2019-02-01 11:22:52      阅读:865      评论:0      收藏:0      [点我收藏+]

标签:配置   video   lap   app   rom   blog   ica   src   startup   

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

 

配置Https 和 HSTS

标签:配置   video   lap   app   rom   blog   ica   src   startup   

原文地址:https://www.cnblogs.com/Ken-Cai/p/10344808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!