2010-08-31 89 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"