.Net how to operate IIS (the principle of) Author: Flying www.ASPCool.com Time: 2002-6-9 15:21:09 Views: 7291
The day before 9CBS saw someone asked how to use the C # operation IIS, I wanted to write a writing in this regard before I had a little time, I had a little bit of time. Before writing this article, I took the time for a day, I wrote a class of IIS (I can call it after compile), further simplify the operation, the source code will be passed out, and some test procedures, Interested friends can download here. The .NET actually has been doing well in this regard. Among the FCL provides a lot of classes to help us complete this work and make our development work very simple and happy. Programming Control IIS is actually very simple, like ASP, and ADSI needs to use ADSI to operate IIS, but we will no longer need GetObject this stuff, because .NET provides us with a more powerful new Stuff. System.directoryServices Namespace includes some powerful stuff-DirectoryEntry, DirectoryEntries, which provides us with powerful features for accessing the active directory, allowing us to operate IIS, LDAP, NDS, and Winnt, which is very powerful. :) But we only talk about IIS control, in general, our operation IIS is generally the operation of the virtual directory, so I will list this as the main content. First we have to figure out the problem of IIS's hierarchical structure. Here is a picture I found abroad. It is very good explanation of IIS's hierarchical structure: In order to figure out the syntax of IIS, we must figure out the picture. Understand the hierarchy of IIS metadata. Each of the figures is called KEY, and each Key can contain one or more values, which is the property we say, the key in the IIS metadata is consistent with the elements in IIS, so The setting of the attribute value in the data affects the settings in IIS. This is the basic idea and core of our programming. Also have a look at the concept of Schema. It represents the name of the architecture in the IIS, you can understand the type of Key in the IIS metadata, specifically, means the type of each node. We know that there is a virtual directory, ordinary directory, and files in the IIS, which belongs to the elements of IIS, distinguishing their flags are Schema. For example, the schema of the virtual directory is "Iisvirtualdir", the ordinary directory is "Iiswebdir". This way we add and delete the directory, IIS know that we add a virtual directory or a normal directory. Creating a virtual directory DirectoryEntry is a big gift for us. His name We know his function - the entrance of the catalog.
People who have used ADSI know that when operating IIS, Winnt, we also need to provide their PATH. When you operate IIS, this path format is: IIS: // computername / service / Website / Directory Computename: That's a server Name, can be named or IP, often used by localhost service: the server, IIS has web, there is FTP, and SMTP these services, we mainly operate IIS's web feature, so "here is" W3SVC, if FTP should be "MSFTPSVC" Website: A lot of sites can be included in an IIS service, which is used to set up a site. His value is a number, default is 1, indicating the default site, if there is anything, then push from 1. Directory: Don't say, the directory name of the operation, a site general top-level directory is "root", and other directory is his child (Child). First we get a top-level directory (root directory): DirectoryEntry Rootfolder = New DirectoryEntry ("IIS: // LocalHost / W3SVC / 1 / root"); if we create this object, it is true that this directory is true. existing. Let's add a new virtual directory, such as what we have to add "ASPCN": DirectoryEntry newvirdir = rootfolder.children.add ("ASPCN", "IisWebVirtualDir"); NewVirdir.Invoke ("AppCreate", true); newvirdir. Commitfolder.commitchanges (); Create a directory's ideas, that is, add a record in the subset of the root directory (rootfolder.children), use the add method in the DirectoryEntries class, which is returned. A DirectoryEntry, indicating the newly joined directory, the first parameter is the name of the virtual directory, the second is the class name of Schema to indicate the type of directory we join. Then use DirectoryEntry's Invoke method, call the "AppCreate" method in ADSI to truly create (seek not going this step can also create a directory success, but for insurance, everyone still uses it), and finally call new, The COMMITCHANGES method of the root directory confirms this operation. When you create a new directory, we can also assign a value to this directory at the same time, but my actual experience tells me that it is best not to do this. If you create it, you will have a lot of attributes that you can't assign a value, such as important representation. The PATH property of the directory. So the flying knife suggests that everyone is best to create a directory, then assign the value, that is, update the directory information. Updating the virtual directory believes that everyone is more familiar with IIS, understands some important settings in IIS, such as readable (AccessWrite), executable (AccessExecute), etc.