2010-03-23 3 views
1

J'utilise la fonction suivante pour créer une application IIS7 et/ou un répertoire virtuel.Modifier le pool d'applications par défaut dans IIS7 à l'aide de .net?

Comment puis-je également définir l'application pour utiliser un pool d'applications différent?

Private Sub CreateVirtualDir(ByVal WebSite As String, ByVal AppName As String, ByVal Path As String, Optional ByVal IsApplication As Boolean = True, Optional ByVal RunScripts As Boolean = True, Optional ByVal IsWrite As Boolean = True) 

    Dim IISSchema As New System.DirectoryServices.DirectoryEntry(_ 
      "IIS://" & WebSite & "/Schema/AppIsolated") 
    Dim CanCreate As Boolean = _ 
    Not IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN" 

    IISSchema.Dispose() 

    If CanCreate Then 
    Dim PathCreated As Boolean 

    Try 
    Dim IISAdmin As New System.DirectoryServices.DirectoryEntry(_ 
      "IIS://" & WebSite & "/W3SVC/1/Root") 

    ''make sure folder exists 
    If Not System.IO.Directory.Exists(Path) Then 
     System.IO.Directory.CreateDirectory(Path) 
     PathCreated = True 
    End If 

    ''If the virtual directory already exists then delete it 
    For Each VD As System.DirectoryServices.DirectoryEntry In IISAdmin.Children 
     If VD.Name = AppName Then 
     IISAdmin.Invoke("Delete", New String() {VD.SchemaClassName, AppName}) 
     IISAdmin.CommitChanges() 
     Exit For 
     End If 
    Next VD 

    ''Create and setup new virtual directory 
    Dim VDir As System.DirectoryServices.DirectoryEntry = _ 
        IISAdmin.Children.Add(AppName, "IIsWebVirtualDir") 

    VDir.Properties("Path").Item(0) = Path 
    If IsApplication Then 
     VDir.Properties("AppFriendlyName").Item(0) = AppName 
    End If 
    VDir.Properties("EnableDirBrowsing").Item(0) = False 
    VDir.Properties("AccessRead").Item(0) = True 
    VDir.Properties("AccessExecute").Item(0) = False 
    VDir.Properties("AccessWrite").Item(0) = IsWrite 
    VDir.Properties("AccessScript").Item(0) = RunScripts 
    VDir.Properties("AuthNTLM").Item(0) = True 
    VDir.Properties("EnableDefaultDoc").Item(0) = True 
    VDir.Properties("DefaultDoc").Item(0) = "default.htm,default.aspx,default.asp" 
    VDir.Properties("AspEnableParentPaths").Item(0) = True 
    ''VDir.Properties("AppCreate").Item(0) = False 
    VDir.CommitChanges() 

    ''the following are acceptable params 
    ''INPROC = 0 
    ''OUTPROC = 1 
    ''POOLED = 2 
    If IsApplication Then 
     VDir.Invoke("AppCreate", 1) 
    Else 
     VDir.Invoke("AppCreate", False) 
    End If 
    Catch Ex As Exception 
    If PathCreated Then 
     System.IO.Directory.Delete(Path) 
    End If 
    ''MsgBox(Ex.Message) 
    End Try 
    End If 
End Sub 

Répondre

1

Juste avant que vous ne VDir.CommitChanges() insérer cette ligne:

VDir.Properties("AppPoolId").Item(0) = "<your_app_pool_name>" 
+0

En fait - qui ne fonctionne pas après tout. Y a-t-il un autre paramètre qui doit aller de pair avec cela ou quelque chose? J'ai même essayé de changer le VDir.Invoke ("AppCreate", 1) en VDir.Invoke ("AppCreate", 2) pour POOLED mais cela ne fonctionnait pas non plus. – EdenMachine

+0

@EdenMachine - J'ai exécuté votre code localement et cela a fonctionné bien. Avez-vous vraiment besoin d'utiliser System.DirectoryServices? Il est beaucoup plus facile de le faire en utilisant Microsoft.Web.Administration sur IIS7.x. – Kev

+0

Oui, j'utilise tout cela - je vais continuer à essayer si vous êtes capable de le faire fonctionner. – EdenMachine

Questions connexes