通过Web部署项目更改应用程序池

问题描述:

有没有办法配置Visual Studio 2005 Web部署项目来将应用程序安装到指定的应用程序池而不是给定网站的默认应用程序池?通过Web部署项目更改应用程序池

有一个很好的文章描述这里定制动作: 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

您可以使用CustomAction部署期间修改IIS,这里是一个文章如何做到这一点: Modifying Internet Information Services During Deployment with Custom Actions

文章是在VB.Net中的例子,并没有明确说明如何改变应用程序池,但应该很容易弄明白。