First I need to create a virtual directory under IIS, with the Direcotryentry this class, how can not, the general report! [System.Runtime.InteropServices.COMException] {"Unknown error (0x80005000)"}
This error.
private static void Testdirectoryentry ()
{
Try
{
String path = "iiswebservice://" + System.Environment.MachineName + "/w3svc";
System.Collections.ArrayList webSite = new System.Collections.ArrayList ();
DirectoryEntry IIS = new DirectoryEntry ("Iis://localhost/w3svc");
if (IIS!= null)
{
foreach (DirectoryEntry entry in IIS. Children)
{
if (String.Compare (entry). schemaClassName, "iiswebserver") = = 0)
{
Console.WriteLine (entry. Name);
Console.WriteLine (entry. properties["ServerComment"]. Value.tostring ());
Console.WriteLine (entry. Path);
}
Console.WriteLine ();
}
}
}
catch (Exception ex)
{
Console.WriteLine (ex. message);
Console.WriteLine (ex. StackTrace);
}
}
And then frantically looking for the reason
The first step is to find problems with the safety of the machine. I IIS7 is installed on the Windows server2008. I canceled the system's UAC. and run this program as Administrator. The result is still not good.
The second step is to find someone on the internet who has the same problem with me. Really A lot of people have, online solutions are:
The IIS Metabase and IIS6 Configuration compatibility is isn't automatically installed when you enable the Web Server role I N Windows 2008 Server. If you enable this feature, the your old DirectoryServices code into. NET should work like it used to.
Need to install IIS6 Metabase compatibility components
It was a success with this plan! But it's not over.
Step three: Find the reason why IIS7 can't use this method!
Kung Fu pays off!