2008-10-03 90 views

回答

12

有一個很好的文章描述這裏定製動作: ScottGu's Blog

你問的是通過「瑞恩」的評論中途回答了有關的問題,不幸的是它在VB,但它不應該是很難翻譯:

Private Sub assignApplicationPool(ByVal WebSite As String, ByVal Vdir As String, ByVal appPool As String) 
    Try 
    Dim IISVdir As New DirectoryEntry(String.Format("IIS://{0}/W3SVC/1/Root/{1}", WebSite, Vdir)) 
    IISVdir.Properties.Item("AppPoolId").Item(0) = appPool 
    IISVdir.CommitChanges() 
    Catch ex As Exception 
    Throw ex 
    End Try 
End Sub 

Private strServer As String = "localhost" 
Private strRootSubPath As String = "/W3SVC/1/Root" 
Private strSchema As String = "IIsWebVirtualDir" 
Public Overrides Sub Install(ByVal stateSaver As IDictionary) 
    MyBase.Install(stateSaver) 
    Try 
    Dim webAppName As String = MyBase.Context.Parameters.Item("TARGETVDIR").ToString 
    Dim vdirName As String = MyBase.Context.Parameters.Item("COMMONVDIR").ToString 
    Me.assignApplicationPool(Me.strServer, MyBase.Context.Parameters.Item("TARGETVDIR").ToString, MyBase.Context.Parameters.Item("APPPOOL").ToString) 
    Catch ex As Exception 
    Throw ex 
    End Try 
End Sub 

... APPPOOL作爲自定義操作中的參數提供的位置。

+1

我正在爲我的設置中的2個網絡應用程序執行此操作 - 它對第二個Web應用程序「Web自定義文件夾」非常有用,但對於默認情況下獲得的「Web應用程序文件夾」在自定義操作期間設置應用程序池 - 但在完成後將其設置回默認應用程序。 – Mampersat 2012-04-04 14:26:53