C# 确定网站的协议

C# 确定网站的协议,c#,iis-6,c#-2.0,iis-5,C#,Iis 6,C# 2.0,Iis 5,我正在使用iis6。 我需要确定某个站点是否在http或https下运行 我尝试使用“DirectoryEntry”从以下位置提取所有属性:IIS://localhost/W3SVC/1在本例中是站点id 以下是结果。 如果有人知道使用“DirectoryEntry”以编程方式确定IIS6协议类型的任何其他方法,请告诉我 AccessFlags = 513 AppIsolated = 2 KeyType = IIsWebVirtualDir Path = c:\inetpub\wwwro

我正在使用iis6。 我需要确定某个站点是否在http或https下运行

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

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

AccessFlags = 513 AppIsolated = 2 KeyType = IIsWebVirtualDir Path = c:\inetpub\wwwroot AppRoot = /LM/W3SVC/1/ROOT AppFriendlyName = Default Application DefaultDoc = Default.htm,Default.asp,index.htm,iisstart.asp AnonymousPasswordSync = True DirBrowseFlags = 1073741886 CacheISAPI = True CGITimeout = 300 AuthFlags = 1 ContentIndexed = True AspLogErrorRequests = True AspScriptFileCacheSize = 250 AspScriptEngineCacheMax = 125 AspExceptionCatchEnable = True AspTrackThreadingModel = False AspAllowOutOfProcComponents = True AspEnableAspHtmlFallback = False AspEnableChunkedEncoding = True AspEnableTypelibCache = True AspErrorsToNTLog = False AspProcessorThreadMax = 25 AspRequestQueueMax = 3000 AspMaxDiskTemplateCacheFiles = 1000 AspAllowSessionState = True AspBufferingOn = True 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 AnonymousUserName = IUSR_MASTER AspScriptLanguage = VBScript AspScriptErrorMessage = An error occurred on the server when processing the URL. Please contact the system administrator. AnonymousUserPass = wl60A8PT[Cp@hE AspDiskTemplateCacheDirectory = %windir%\system32\inetsrv\ASP Compiled Templates HttpCustomHeaders = X-Powered-By: ASP.NET KeyType = IIsCertMapper 其中任何一个能告诉我协议是Http还是Https吗?
如果不是。。。有人知道如何在IIS 6上使用C进行检查吗?

如果您可以等到收到请求后再使用。

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

Configuration.AppSettings(<key>)

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

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

如果设置了AccessSSL hex 0x00000008标志,则表示如果http不可用,则需要SSL-ie https

通常,您必须在IIS Web服务器根目录上检查此属性,因为IIS逻辑基于虚拟目录


Path->IIS://localhost/W3SVC/1/Root

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

我在自己的WindowsServer2003上使用SSL和非SSL站点测试了以下代码段

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:

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

这是一个相当丑陋的解决方案。。。我在寻找一些平滑的东西,这些提示只说明在哪个主机上:端口该站点将接受SSL连接,它不能确保此网站的SSL通信可用/需要。在我看来,AccessSlFlags只确定访问对象是否需要SSL连接,不是站点是否有SSL绑定。是的,问题是:我需要确定某个站点是否在http或https下运行。如果设置了AccessSSL hex 0x00000008标志,则表示需要SSL-ie https,如果http不可用,则需要编辑以添加此标志。如果问题是如何确定是否可以使用https连接到某个站点,则问题必须更具体:带有服务器证书或客户端证书的https:IIS配置可能不同。“运行”是什么意思?我的站点可能同时具有http和https绑定。