Method for managing Using code of IIS application pool

zhaozj2021-02-12  140

Using system; using system.directoryservices; usingspace adsi1 {///////

/// small class containing methods to configure IIS. ///

Class Configiis

{

///

/// The main entry point for the application. ///

[Stathread]

// Main program entrance, which you can choose, I have written it for convenience and all the features.

Static void main (string [] args)

{

String AppPoolName = "MyAppPool";

String newvdir1 = "myvdir";

DirectoryEntry newvdir = Createvdir (newvdir1);

CreateAppPool (AppPoLName);

AssignAppPool (Newvdir, AppPoolname);

ConfigAppPool ( "Stop", AppPoolName);} // create a virtual directory static DirectoryEntry CreateVDir (string vdirname) {DirectoryEntry newvdir; DirectoryEntry root = new DirectoryEntry ( "IIS: // localhost / W3SVC / 1 / Root"); newvdir = root .Children.add (vdirname, "iiswebvirtualdir); newvdir.properties [" path "] [0] =" c: // inetpub // wwwroot "; newvdir.properties [" AccessScript "] [0] = true; newvdir .Commitchanges (); return newvdir;} // Create a new application pool. static void CreateAppPool (string AppPoolName) {DirectoryEntry newpool; DirectoryEntry apppools = new DirectoryEntry ( "IIS: // localhost / W3SVC / AppPools"); newpool = apppools.Children.Add (AppPoolName, "IIsApplicationPool"); newpool.CommitChanges () } Static void AssignApppool (DirectoryEntry Newvdir, String Appoolname) {Object [] param = {0, apppoolname, true}; newvdir.invoke ("appcreate3", param;}

// method is a method of managing application pool, there are three Start, Stop, Recycle, and AppPoolName is the application pool name static void ConfigAppPool (string method, string AppPoolName) {DirectoryEntry appPool = new DirectoryEntry ( "IIS: // localhost / W3SVC / AppPools "); DirectoryEntry findPool = appPool.Children.Find (AppPoolName, IIsApplicationPool"); findPool.Invoke (method, null); appPool.CommitChanges (); appPool.Close ();} // list of applications pools static void AppPoolList () {DirectoryEntry appPool = new DirectoryEntry ( "IIS: // localhost / W3SVC / AppPools"); foreach (DirectoryEntry a in appPool.Children) {Console.WriteLine (a.Name);}}

Private void vdirToApppople () {DirectroryEntry VD = New DirectoryEntry ("IIS: // LocalHost / W3SVC / 1 / Root / CCC"); console.writeline (vd.properties ["apppoolid"]. value.toString ());} }

转载请注明原文地址:https://www.9cbs.com/read-6742.html

New Post(0)