【问题标题】:Determine protocol for website确定网站协议
【发布时间】:2011-04-06 04:22:39
【问题描述】:

我正在使用 IIS 6。 我需要确定某个站点是在http还是https下运行。

我尝试使用“DirectoryEntry”从以下位置提取所有属性:IIS://localhost/W3SVC/1(1 是本示例中的站点 ID)

以下是结果。 如果有人知道使用“DirectoryEntry”以编程方式确定 IIS6 协议类型的任何其他方式 - 请告诉我

访问标志 = 513 应用隔离 = 2 KeyType = IIsWebVirtualDir 路径 = c:\inetpub\wwwroot AppRoot = /LM/W3SVC/1/ROOT AppFriendlyName = 默认应用程序 DefaultDoc = Default.htm,Default.asp,index.htm,iisstart.asp AnonymousPasswordSync = True 目录浏览标志 = 1073741886 CacheISAPI = 真 CGI超时 = 300 授权标志 = 1 内容索引 = 真 AspLogErrorRequests = True AspScriptFileCacheSize = 250 AspScriptEngineCacheMax = 125 AspExceptionCatchEnable = True AspTrackThreadingModel = False AspAllowOutOfProcComponents = True AspEnableAspHtmlFallback = False AspEnableChunkedEncoding = True AspEnableTypelibCache = True AspErrorsToNTLog = 假 AspProcessorThreadMax = 25 AspRequestQueueMax = 3000 AspMaxDiskTemplateCacheFiles = 1000 AspAllowSessionState = 真 AspBufferingOn = 真 AspEnableParentPaths = True AspSessionTimeout = 20 AspQueueTimeout = -1 AspCodepage = 0 AspScriptTimeout = 90 AspScriptErrorSentToBrowser = True AppAllowDebugging = False AppAllowClientDebug = False AspKeepSessionIDSecure = False AspEnableApplicationRestart = True AspQueueConnectionTestTime = 3 AspSessionMax = -1 AspLCID = 2048 匿名用户名 = IUSR_MASTER AspScriptLanguage = VBScript AspScriptErrorMessage = 处理 URL 时服务器发生错误。请联系系统管理员。 AnonymousUserPass = wl60A8PT[Cp@hE AspDiskTemplateCacheDirectory = %windir%\system32\inetsrv\ASP 编译模板 HttpCustomHeaders = X-Powered-By: ASP.NET KeyType = IIsCertMapper

这些可以告诉我协议是 Http 还是 Https? 如果没有...有谁知道如何在 IIS 6 上使用 C# 检查它?

【问题讨论】:

  • “跑步”是什么意思?我的站点可以同时具有 http 和 https 绑定。

标签: c# iis-6 c#-2.0 iis-5


【解决方案1】:

当然:IIS AccessSSLFlags 属性包含这些信息。

如果设置了AccessSSL(十六进制0x00000008)标志,则意味着需要SSL-即https-,如果没有http可用。

像往常一样,您必须在 IIS WebServer 根目录上检查此属性,因为 IIS 逻辑基于虚拟目录。

路径 -> IIS://localhost/W3SVC/1/Root

【讨论】:

  • 在我看来,AccessSSLFlags 仅确定 SSL 连接是否需要来访问对象,而不是站点是否存在 SSL 绑定。
  • 是的,来自问题:“我需要确定某个站点是在 http 还是 https 下运行”。如果设置了 AccessSSL (hex 0x00000008) 标志,则意味着 SSL -ie https- 是必需的,如果没有 http 可用(编辑添加此)。如果问题是“我如何确定是否可以使用 https 连接到某个站点”,则问题必须更具体:带有服务器证书或客户端证书的 https:IIS 配置可能不同。
【解决方案2】:

看起来您需要查看使用 IIsWebServer 对象的 SecureBindings 属性。

我在自己的 Windows Server 2003 上使用 SSL 和非 SSL 站点测试了以下代码 sn-p。

DirectoryEntry di = new DirectoryEntry("IIS://prodweb1/W3SVC/1");
PropertyValueCollection sslCertHashProperty = di.Properties["SSLCertHash"];
if (sslCertHashProperty.Count > 0)
{
  Console.WriteLine("Site has associated SSL Certificate.");
}
PropertyValueCollection secureBindingsProperty = di.Properties["SecureBindings"];
if (secureBindingsProperty.Count > 0)
{
  Console.WriteLine("Site has at least one SSL (https) binding.");
}
PropertyValueCollection serverBindingsProperty = di.Properties["ServerBindings"];
if (serverBindingsProperty.Count > 0)
{
  Console.WriteLine("Site has at least one non-SSL (http) binding.");
}

【讨论】:

  • 绑定只说明站点将在哪个主机:端口上接受 SSL 连接,它并不能确保 SSL 通信对于该网站可用/需要。
【解决方案3】:

您可以使用元数据库来判断。我不知道为什么它不在你的输出中,但应该有一个属性,比如 IsSecure=true 来指示需要 ssl。如果 ssl 是可选的,我认为不会设置此属性。

【讨论】:

    【解决方案4】:

    如果您可以等到收到请求,您可以使用Request.IsSecureConnection

    【讨论】:

    • 这是一个非常丑陋的解决方案......我正在寻找更流畅的东西
    【解决方案5】:

    不太精通 C#,但我相信您可以在应用程序中加载 web.config 信息。在那里你应该能够看到是否有一个特定的安全密钥表明在服务器上配置了 SSL。

    Configuration.AppSettings(<key>)
    

    【讨论】:

      【解决方案6】:

      您可以检查请求对象。 如果正在使用 SSL:

      HttpContext.Current.Request.ServerVariables["HTTPS"].ToLower() == "on"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-03
        • 2014-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-03
        • 2013-12-27
        • 2021-06-21
        相关资源
        最近更新 更多