Manage IIS7 programmatically in C #

Source: Internet
Author: User
Tags iis metabase

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.