First, I need to create a virtual directory under IIS. I use the direcotryentry class. Why not? It will always be reported! [System. runtime. interopservices. comexception] {"Unknown error (0x80005000 )"}
This error occurs.
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 );
}
}
Then I went crazy to find the reason.
Step 1: Find out the security issues on the machine. I installed iis7 on Windows server2008. I canceled the UAC of the system. Run the program as an administrator. The result still does not work.
Step 2: Find someone on the Internet that has the same problem with me. Sure enough! Many people have the following solutions:
The IIS metabase and IIS6 configuration compatibility is not automatically installed when you enable the Web server role in Windows 2008 server. if you enable this feature, your old directoryservices code in. net shoshould work like it used.
IIS6 metabase compatibility component needs to be installed
This solution is successful! But it is not over.
Step 3: Find the reason why iis7 cannot use this method!
Hard work!
Iis7 has no metadata. Ah ~~ This is the root cause. You can go to the c: \ windows \ system32 \ inetsrv directory to check whether IIS6 and iis7 files are different.
So I found this method later:
Http://dflying.cnblogs.com/archive/2006/04/17/377276.html)
Microsoft provides some very powerful APIs for managing iis7 --Microsoft. Web. AdministrationAllows us to manage and set IIS 7 configuration programmatically. Microsoft. Web. Administration. dll is located in the IIS Directory (% WINDIR % \ system32 \ inetsrv). After you add a reference to it in the project, you can use these Apis. Displays the main objects in Microsoft. Web. Administration. dll.
Let's use Microsoft. Web. administration through several examples. The examples below are easy to understand and I will not explain them too much.
Create a site)
Servermanager iismanager = new servermanager ();
Iismanager. sites. Add ("newsite", "HTTP", "*: 8080:", "d: \ mysite ");
Iismanager. Update ();
Add an application to a site
Servermanager iismanager = new servermanager ();
Iismanager. sites ["newsite"]. Applications. Add ("/sales", "d: \ MyApp ");
Iismanager. Update ();
Create a virtual directory (Virtual directory)
Servermanager iismanager = new servermanager ();
Application APP = iismanager. sites ["newsite"]. Applications ["/sales"];
App. virtualdirectories. Add ("/vdir", "d: \ myvdir ");
Iismanager. Update ();
Runtime control: Stop a site
Servermanager iismanager = new servermanager ();
Iismanager. sites ["newsite"]. Stop ();
Runtime control: reclaim the application pool (Recyciling an application pool)
Servermanager iismanager = new servermanager ();
Iismanager. applicationpools ["defaultapppool"]. Recycle ();
Runtime control: Get the request currently being processed
Servermanager iismanager = new servermanager ();
Foreach (workerprocess w3wp in iismanager. workerprocesses ){
Console. writeline ("w3wp ({0})", w3wp. processid );
Foreach (request in w3wp. getrequests (0 )){
Console. writeline ("{0}-{1}, {2}, {3 }",
Request. url,
Request. clientipaddr,
Request. timeelapsed,
Request. timeinstate );
}
}
OK. The problem is solved from the root. Hope to help you with the same problem!