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

时间:2020-03-06 15:04:44  来源:igfitidea点击:

有没有一种方法可以配置Visual Studio 2005 Web部署项目,以将应用程序安装到给定网站的命名应用程序池中,而不是默认应用程序池中?

解决方案

这里有一篇很好的文章描述了自定义操作:
ScottGu的博客

我们提出的问题在" Ryan"的评论中途已经得到回答,很遗憾,它在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作为参数提供的位置。

我们可以在部署过程中使用CustomAction来修改IIS,这是一篇文章介绍的方法:
在部署期间使用自定义操作修改Internet信息服务

本文中的示例在VB.Net中,没有明确显示如何更改应用程序池,但是应该很容易弄清楚。