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

时间:2008-10-03 14:45:45

标签: c# deployment windows-installer asp.net-2.0

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

2 个答案:

答案 0 :(得分:12)

这里有一篇描述自定义操作的好文章: ScottGu's Blog

你提出的问题在'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在自定义操作中作为参数提供。

答案 1 :(得分:3)

您可以在部署期间使用CustomAction修改IIS,以下是一篇如何执行此操作的文章: Modifying Internet Information Services During Deployment with Custom Actions

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