You can add a website using Add method that is present in the Sites collection of ServerManager. Below is the code snippet which creates an application Pool, and then creates a site, also enables the FREB and commit the changes to the IIS7 configuration file:
ServerManager serverMgr = new ServerManager();
Site mySite = serverMgr.Sites.Add("MySiteName", "C:\\inetpub\\wwwroot", 8080);
serverMgr.ApplicationPools.Add("MyAppPool");
mySite.ApplicationDefaults.ApplicationPoolName = "MyAppPool";
mySite.TraceFailedRequestsLogging.Enabled = true;
mySite.TraceFailedRequestsLogging.Directory = "C:\\inetpub\\customfolder\\site";
serverMgr.CommitChanges();
Now, let's try to delete the same website created. As you know earlier, in IIS7, you need to give an unique name for each website (which was not the case in IIS 6.0).
Site s1 = serverMgr.Sites["MySiteName"]; // you can pass the site name or the site ID
serverMgr.Sites.Remove(s1);
serverMgr.CommitChanges();
That was very simple correct? what are you waiting for? ExploreMicrosoft.Web.Administration.dll more. You will love it! Again, IIS7 is the best friend to the developers!
No comments:
Write comments