Fork me on GitHub

一步一步学习IdentityServer3 (14) 启用Https

申领一个CA证书,我用了一个腾讯的免费证书night-c.cn,这是腾讯云买域名送的一个证书 是单域名,非泛域名

1:安装证书  IIS选择证书

2:将证书加载到Identityserver3中,并启用SSL

 static class Certificate
    {
        public static X509Certificate2 Get()
        {
            var assembly = typeof(Certificate).Assembly;
            using (var stream = assembly.GetManifestResourceStream("OAuthWeb.IdrConfig.night-c.cn.pfx"))
            {
                
                return new X509Certificate2(ReadStream(stream),"密码");
            }
        }

        private static byte[] ReadStream(Stream input)
        {
            byte[] buffer = new byte[16 * 2048];
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }
    }
 RequireSsl = true,

我在本地Host文件映射了下域名就OK了 注意https是443端口 需要开下 如下图搞定

 

posted @ 2017-11-17 15:51  龙码精神  阅读(784)  评论(0编辑  收藏  举报