c# - 设置服务器名称指示 (SNI) 取消证书绑定(bind)

标签 c# iis wix iis-8.5

我正在使用 Microsoft.Web.Administration(在 Wix CustomAction 内)来配置服务器名称指示并绑定(bind)到 IIS 8.5 站点上的现有服务器证书。

事实证明,设置 SNI 可以解除证书绑定(bind)。下面的代码将使事情变得更清楚:

using Microsoft.Web.Administration;

var binding = site.Bindings.FirstOrDefault(x => x.IsIPPortHostBinding && x.Host == sitename);

binding.CertificateHash = certificate.GetCertHash();
binding.CertificateStoreName = store.Name;

// this statement is causing the certificate info to get messed up.
binding["sslFlags"] = 1; // or binding.SetAttributeValue("sslFlags", 1);

结果:

绑定(bind)["sslFlags"] = 1; enter image description here

没有 绑定(bind)["sslFlags"] = 1; enter image description here

这是一个错误还是我遗漏了什么?如何让 SNI 和证书绑定(bind)保持一致?

最佳答案

看来 Microsoft.Web.Administration v7.0 是这里的罪魁祸首。这是 NuGet gallery 上的官方版本,似乎主要适用于 IIS 7(我的意思是它适用于 IIS 7 和 8 中常见的功能,但 7 没有的任何功能都会产生像上面这样的奇怪结果) .

使用IIS.Microsoft.Web.Adminstration (这似乎是 IIS 8.5 的社区上传的包)可以工作。从此answer得到提示.

更新的代码:

binding.CertificateHash = certificate.GetCertHash();
binding.CertificateStoreName = store.Name;

binding.SslFlags = SslFlags.Sni;  // <<< notice it has helpful enums

关于c# - 设置服务器名称指示 (SNI) 取消证书绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30536005/

相关文章:

visual-studio - 为什么wix项目会出错?

c# - 如何使用 GeckoFX 作为 XULRunner 的包装器在 javascript 中调用 C# 方法

c# - 缓存数据记录器数据的方法

c# - 阻止发送邮件

c# - C# 索引器是否返回变量或值?

jquery - 请求 jQuery 时出现查询字符串是什么原因?例如/jquery-1.3.2.min.js?_=12553

asp.net - 您无权访问 IIS 配置文件 - Web 应用程序错误

asp.net - System.Diagnostics.Trace 在 ApplicationPoolIdentity 下的 Web 应用程序中不起作用

windows - WiX Bootstrapper 在退出时运行可执行文件

c# - 使用条件操作创建 WIX 安装程序