【发布时间】:2009-03-18 15:09:57
【问题描述】:
我需要部署我的网络服务。它需要使用自己的凭据在 IIS 中的单独应用程序池中运行。
是否可以通过在 VS 2008 中使用 Web 设置项目来做到这一点?
默认情况下,我似乎只能选择现有的应用程序池。
【问题讨论】:
标签: c# web-services iis iis-6 windows-installer
我需要部署我的网络服务。它需要使用自己的凭据在 IIS 中的单独应用程序池中运行。
是否可以通过在 VS 2008 中使用 Web 设置项目来做到这一点?
默认情况下,我似乎只能选择现有的应用程序池。
【问题讨论】:
标签: c# web-services iis iis-6 windows-installer
查看这篇帖子http://forums.iis.net/t/1061734.aspx,它将对 Microsoft.Web.Administration dll 提供一些粗略的了解。
我还没有研究过整个概念,但我想出了如何创建新池以及如何附加新网站/虚拟目录。
创建应用程序池
Microsoft.Web.Administration.ServerManager manager = new Microsoft.Web.Administration.ServerManager();
manager.ApplicationPools.Add("NewApplicationPool");
manager.CommitChanges();
附加到现有的虚拟目录
Microsoft.Web.Administration.ServerManager manager = new Microsoft.Web.Administration.ServerManager();
Site defaultSite = manager.Sites["Default Web Site"];
// defaultSite.Applications will give you the list of 'this' web site reference and all
// virtual directories inside it -- 0 index is web site itself.
Microsoft.Web.Administration.Application oVDir = defaultSite.Applications["/myApp"];
oVDir.ApplicationPoolName = "NewApplicationPool";
manager.CommitChanges();
这样您可以使用自定义操作将应用程序池分配给您的新网站,覆盖安装程序类的提交方法。
如果仍然觉得自己很苦恼,请告诉我,我会尝试发送代码。
问候 法亚兹 faiyazkhan@hotmail.com
【讨论】:
我以前曾走这条路,不幸的是,您需要手动创建应用程序池或编写自定义操作来为您管理它。
在下面的 cmets 中进一步回答 Grzenio 的问题:
“您能否给我一个提示,从哪里开始寻找代码/帮助程序类?您是将您的项目保留为 Web 设置项目,还是只使用标准应用程序设置项目?”
我在包含安装项目的解决方案中添加了一个名为 InstallHelper 的新项目。在那个项目中,我创建了一个名为 InstallActions 的类,它源自:
System.Configuration.Install.Installer (MSDN)。
您可以在 Installer 基类上覆盖四种方法,以允许您根据安装程序运行时是否处于安装、提交、卸载或回滚阶段来指定自定义操作。
我还在设置项目用户界面中添加了一些文本框对话框。从这些对话中捕获的输入和状态通过字典传递给您的自定义安装操作。即:
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration.Install;
using System.Windows.Forms;
namespace InstallHelper
{
[RunInstaller(true)]
public partial class PostInstallActions : Installer
{
public override void Install(IDictionary state)
{
base.Install(state);
// Do my custom install actions
}
public override void Commit(IDictionary state)
{
base.Commit(state);
// Do my custom commit actions
}
public override void Uninstall(IDictionary state)
{
base.Uninstall(state);
// Do my custom uninstall actions
}
public override void Rollback(IDictionary state)
{
base.Uninstall(state);
// Do my custom rollback actions
}
}
}
要将您的自定义操作项目添加到设置项目,请打开自定义操作查看器/编辑器并指定 InstallHelper 项目的输出。
这是基础知识,应该可以帮助您入门。 Web 设置项目还支持自定义操作和其他用户输入对话框,因此您可能希望在自定义操作之外重新使用现有项目。
【讨论】: