Recently wrote a scan IIS hosting site and then regularly registered to the consul gadget, random online copy of a Help class, finish the test of the machine is no problem, throw to the server found a huge anomaly.
System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
In System.DirectoryServices.DirectoryEntry.Bind (Boolean throwiffail)
In System.DirectoryServices.DirectoryEntry.Bind ()
In System.DirectoryServices.DirectoryEntry.get_IsContainer ()
In System.DirectoryServices.DirectoryEntries.ChildEnumerator. ctor (DirectoryEntry Container)
We checked the data and found out that:
This exception code indicates that the IIS://LOCALHOST/W3SVC/1 ADSI provider does not exist or is inaccessible.
Open IIS Manager you can see that the server's localhost (that is, the default site) is present and running, and the primary site ID is indeed 1. This indicates that the problem is with ADSI provider that appears in IIS://LocalHost.
Frankly, IIS 7 does not have ADSI provider installed by default.
Solution: Control Panel, programs and features, Panel on the left, open or close Windows features, Web Server (IIS), Administrative Tools, IIS 6 Management compatibility, IIS metabase compatibility.
The code section is relatively straightforward:
usingsystem.serviceprocess;usingSystem.DirectoryServices; Public classiismanager{ Public StaticList<iiswebserviceinfo>GETLOCALWEBSERIVICEINFO_IIS6 () {DirectoryEntry RootFolder=NewDirectoryEntry ("Iis://localhost/w3svc"); foreach(DirectoryEntry ChildinchRootFolder. Children) {if(Child. schemaClassName = ="IIsWebServer") {child. properties["ServerComment"]. Value.tostring ();//Service NameChild. properties["serverstate"]. Value;//Service StatusChild. properties["ServerBindings"]. Value;//binding Information } } } }
The disadvantage is more obvious is only support IIS6 and the following version (install ADSI provider), too cumbersome.
IIS7.0 and above for service information you can use Microsoft.web.administration,nuget to search
I have to say that Microsoft is still more difficult to spell. This is going to be a cross-platform rhythm AH (Linux version of IIS is in the corner ...) )
The code is much simpler:
usingMicrosoft.Web.Administration; classProgram {Static voidMain (string[] args) {Servermanager sm=NewServermanager (); foreach(varSinchSM. Sites) {Console.WriteLine ("Site name: {0}", S.name); Console.WriteLine ("running status: {0}", s.state.tostring ()); foreach(varTmpinchs.bindings) {System.Console.WriteLine ("\ t type: {0}", TMP. PROTOCOL); System.Console.WriteLine ("\tip Address: {0}", TMP. EndPoint.Address.ToString ()); System.Console.WriteLine ("\ t port: {0}", TMP. EndPoint.Port.ToString ()); System.Console.WriteLine ("\ t host name: {0}", TMP. Host); }} console.readkey (); } }
Of course, getting IIS information on the Windows operating system requires Administrator privileges
. NET get IIS7.0 and above hosting service information