忽略一次点击登录页面的客户端证书弹出窗口 - 但仍需要证书才能获得服务

Ignore client certificate popup for a click once landing page - but still require cert for service

我在 IIS 中托管了一个 WCF 服务,其中包含一个默认的 .aspx 文件,用作 clickonce 应用程序的登录页面。 .svc 文件和.aspx 文件位于应用程序的同一根目录中:即以下文件夹结构:

MyService
 --  MyService.svc
 --  Default.aspx
 --  Web.config

如果我从 IIS 浏览 MyService 并查看 Default.aspx(我的点击一次登录页面),我不想被提示输入客户端证书,因为客户端证书实际上直接从单击一次中选择并附加到 WCF 服务的调用(即 client.ClientCredentials.ClientCertificate.Certificate = UserCertificate;)。

我可以在 IIS 管理器中解决这个问题,方法是将 MyService 应用程序设置为 Ignore 客户端证书并将 MyService.svc 设置为 Accept客户证书。这一切都按预期工作(浏览到 Default.aspx 不会提示我,但浏览到 .svc 会提示我),但出于部署和测试原因,我想在 Web.config 中自动执行此操作。我尝试了以下但没有运气。

<location path="MyService">
<system.webServer>
  <security>
    <access sslFlags="None" />
  </security>
</system.webServer>

<location path="MyService.svc">
<system.webServer>
  <security>
    <access sslFlags="SslRequireCert" />
  </security>
</system.webServer>

我假设将 MyService 设置为 "None" 最初会把它搞砸。

在尝试将我的 svc 移动到另一个文件夹并将其作为 IIS 中的子应用程序时,我也 运行 遇到了类似的问题。

任何帮助都会很棒,谢谢。

我最终通过在我的 Advanced Installer 项目中添加一个自定义操作来解决这个问题,该项目使用类似于

的方式将 XML 配置写入 ApplicationHost.config
    using (ServerManager manager = new ServerManager())
        {
            var config = manager.GetApplicationHostConfiguration();

            try
            {
                ConfigurationSection accessSection = config.GetSection("system.webServer/security/access", site);

                if (accessSection != null)
                {
                    Console.WriteLine("Opened app host config successfully.");
                    accessSection["sslFlags"] = @"None";
                }

                accessSection = config.GetSection("system.webServer/security/access", "Default Web Site/MyService/MyService.svc");

                if (accessSection != null)
                {
                    Console.WriteLine("Opened app host config successfully.");
                    accessSection["sslFlags"] = @"Ssl, SslNegotiateCert, SslRequireCert";
                }

                manager.CommitChanges();
                Console.WriteLine("Successfully committed changes");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to open the app host config.");
            }
        }