C# 如何在 Web 安装项目中创建新的应用程序池?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/658675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I create a new application pool in a Web Setup Project?
提问by Grzenio
I need to deploy my web service. It needs to run in a separate application pool in IIS with its own credentials.
我需要部署我的网络服务。它需要使用自己的凭据在 IIS 中的单独应用程序池中运行。
Is it possible to do this by using a Web Setup Project in VS 2008?
是否可以通过在 VS 2008 中使用 Web 安装项目来做到这一点?
By default, I seem to only be able to choose an existing application pool.
默认情况下,我似乎只能选择现有的应用程序池。
采纳答案by Kev
I've been down this road before and unfortunately you'll need to create the application pool manually or write a Custom Action to manage this for you.
我以前一直在这条路上走,不幸的是,您需要手动创建应用程序池或编写自定义操作来为您管理它。
Further to Grzenio's question in the comments below:
进一步在下面的评论中 Grzenio 的问题:
"Could you give me a hint where to start looking for the code/helper classes? And do you keep your project a Web Setup Project, or just use the standard application setup project?"
“你能给我一个提示,从哪里开始寻找代码/帮助程序类吗?你把你的项目保留为 Web 安装项目,还是只使用标准的应用程序安装项目?”
I added a new project called InstallHelper
to the solution containing the setup project. In that project I created a class called InstallActions
which derives from:
我添加了一个新项目,称为InstallHelper
包含安装项目的解决方案。在那个项目中,我创建了一个名为的类InstallActions
,它派生自:
System.Configuration.Install.Installer
(MSDN).
System.Configuration.Install.Installer
(MSDN)。
There are four methods you can override on the Installer
base class to allow you to specify custom actions depending on whether you're in the Install, Commit, Uninstall or Rollback phases when the installer is running.
您可以在Installer
基类上覆盖四种方法,以允许您根据安装程序运行时是处于安装、提交、卸载还是回滚阶段来指定自定义操作。
I also added a number of text box dialogues to the setup project user interface. Input and state captured from these dialogues is passed to your custom install action via a dictionary. i.e.:
我还在设置项目用户界面中添加了一些文本框对话框。从这些对话中捕获的输入和状态通过字典传递给您的自定义安装操作。IE:
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
}
}
}
To add your custom action project to the setup project, open the Custom Actions viewer/editor and specify the output from the InstallHelper
project.
要将自定义操作项目添加到设置项目,请打开自定义操作查看器/编辑器并指定InstallHelper
项目的输出。
That's the basics and should get you started. The Web Setup Project also supports custom actions and additional user input dialogue boxes, so you may wish to re-use your existing project, in addition to a custom action.
这是基础知识,应该可以帮助您入门。Web Setup Project 还支持自定义操作和附加的用户输入对话框,因此除了自定义操作外,您可能希望重新使用现有项目。
回答by Kev
Check out this post http://forums.iis.net/t/1061734.aspx, it will give some rough idea about Microsoft.Web.Administration dll.
看看这篇文章http://forums.iis.net/t/1061734.aspx,它会给出一些关于 Microsoft.Web.Administration dll 的粗略概念。
I have not studied the whole concept but I figured how to create new pool and how to attach with new web site / virtual directory.
我还没有研究过整个概念,但我想出了如何创建新池以及如何附加新网站/虚拟目录。
Creating Application Pool
创建应用程序池
Microsoft.Web.Administration.ServerManager manager = new Microsoft.Web.Administration.ServerManager();
manager.ApplicationPools.Add("NewApplicationPool");
manager.CommitChanges();
Attaching with existing virtual directory
附加现有的虚拟目录
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();
This way you can assign application pool to your new website using the custom actions, overriding the commit method of installer class.
通过这种方式,您可以使用自定义操作将应用程序池分配给您的新网站,覆盖安装程序类的提交方法。
If still find yourself struggling, please let me know and I'll try to send the code.
如果仍然发现自己在挣扎,请告诉我,我会尝试发送代码。
Regards Faiyaz [email protected]
问候 Faiyaz [email protected]