Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>If you're using IIS7:</strong></p> <p>To create an application pool using and set the .NET Framework version (to v2.0 in this case), do this:</p> <pre><code>using Microsoft.Web.Administration; ... using(ServerManager serverManager = new ServerManager()) { ApplicationPool newPool = serverManager.ApplicationPools.Add("MyNewPool"); newPool.ManagedRuntimeVersion = "v2.0"; serverManager.CommitChanges(); } </code></pre> <p>You should add a reference to <code>Microsoft.Web.Administration.dll</code> which can be found in:</p> <blockquote> <p><code>%SYSTEMROOT%\System32\InetSrv</code></p> </blockquote> <p>To assign a virtual directory to an application pool (though I think you mean an application):</p> <pre><code>using (ServerManager serverManager = new ServerManager()) { // Find Default Website Site site = serverManager.Sites.First(s =&gt; s.Id == 1); Application newApp = site.Applications.Add("/MyNewApp", @"C:\inetpub\wwwroot\mynewapp"); newApp.ApplicationPoolName = "MyNewPool"; serverManager.CommitChanges(); } </code></pre> <p><strong>If you're using IIS6:</strong></p> <pre><code>using (DirectoryEntry appPools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools")) { using (DirectoryEntry newPool = appPools.Children.Add("MyNewPool", "IIsApplicationPool")) { // Just use NetworkService as pool account newPool.Properties["AppPoolIdentityType"].Value = 2; newPool.CommitChanges(); } } </code></pre> <p>The following code creates an application called <code>MyNewApp</code> in the <em>Default Web Site</em> and assigns it to the application pool <code>MyNewPool</code> we created using the code example above:</p> <pre><code>using (DirectoryEntry siteRoot = new DirectoryEntry(@"IIS://Localhost/W3SVC/1/root")) { using (DirectoryEntry newApp = siteRoot.Children.Add("MyNewApp", "IIsWebVirtualDir")) { newApp.Properties["Path"].Value = @"C:\inetpub\wwwroot\mynewapp"; newApp.Properties["AccessScript"][0] = true; newApp.Properties["AccessFlags"].Value = 513; // AccessScript | AccessRead newApp.Properties["AuthFlags"].Value = 7;// AuthAnonymous|AuthBasic|AuthNTLM newApp.Properties["AppIsolated"].Value = "2"; newApp.Properties["AppRoot"].Value = newApp.Path.Replace("IIS://Localhost", "/LM"); newApp.Properties["AppPoolId"].Value = "MyNewPool"; newApp.Properties["AppFriendlyName"].Value = "MyNewApp"; newApp.CommitChanges(); } } </code></pre> <p>I all of the above cases your code needs to be running as an administrator.</p> <p>For more information see:</p> <p><strong>IIS7:</strong></p> <blockquote> <p><a href="http://www.iis.net/ConfigReference" rel="noreferrer">IIS 7 Configuration Reference</a><br> <a href="http://learn.iis.net/page.aspx/165/how-to-use-microsoftwebadministration/" rel="noreferrer">How to Use Microsoft.Web.Administration</a> </p> </blockquote> <p><strong>IIS6:</strong></p> <blockquote> <p><a href="http://msdn.microsoft.com/en-us/library/ms525791%28v=vs.90%29.aspx" rel="noreferrer">Using System.DirectoryServices to Configure IIS</a><br> <a href="http://msdn.microsoft.com/en-us/library/ms524713%28v=VS.90%29.aspx" rel="noreferrer">IIS Programmatic Administration Reference</a><br> <a href="http://msdn.microsoft.com/en-us/library/ms525644%28v=VS.90%29.aspx" rel="noreferrer">IIS Metabase Properties</a></p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload