2010-08-31 86 views
1

我使用IIS 6. 我需要确定某个站点是在http还是https下运行。确定网站的协议

我尝试使用“的DirectoryEntry”从提取的所有属性:IIS://本地主机/ SVC/1(1是该示例中的网站ID)

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

 
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[[email protected] 
AspDiskTemplateCacheDirectory = %windir%\system32\inetsrv\ASP Compiled Templates 
HttpCustomHeaders = X-Powered-By: ASP.NET 
KeyType = IIsCertMapper 

任何一个可以告诉我,如果该协议是HTTP或HTTPS? 如果不是......有人知道如何使用C#在IIS 6上检查它吗?

+1

你是什么意思'跑?'我的网站可能有http和https绑定。 – ScottE 2010-09-10 18:31:50

回答

2

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

如果设置了AccessSSL(十六进制0x00000008)标志,则表示SSL -ie https-是必需的,如果没有http可用。

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

路径 - > IIS://本地主机/ W3SVC/1 /根

+0

在我看来,AccessSSLFlags只决定了是否需要SSL连接_required_来访问该对象,而不是该网站是否存在SSL绑定。 – 2010-09-10 17:42:24

+0

是的,从问题:“我需要确定某个网站是否在http或https下运行”。如果AccessSSL(十六进制0x00000008)标志被设置,这意味着SSL -ie https-是必需的,如果没有http可用(编辑添加此)。如果问题是“我如何确定我是否可以使用https连接到某个站点”,则问题必须更加具体:https与服务器证书或客户端证书:IIS配置可能会有所不同。 – JoeBilly 2010-09-11 09:10:10

-1

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

+0

这是一个非常丑陋的解决方案...我在寻找更平滑的东西 – Nissim 2010-09-06 13:02:14

-1

不是精通C#,但我相信你可以在你的应用程序中加载web.config信息。您应该能够查看是否存在特定的安全密钥,指示服务器上已配置SSL。

Configuration.AppSettings(<key>) 
0

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

1

它看起来像你需要看使用IIsWebServer对象的SecureBindings财产。

我在自己的Windows Server 2003上测试了以下代码片段,包括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."); 
} 
+0

绑定仅表明站点将在哪个主机:端口上接受SSL连接,但不能确保SSL通信对于此网站可用/需要。 – JoeBilly 2010-09-09 08:23:21

-1

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

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