使用 C# 和 IIS7 创建新的应用程序池并将其分配到远程主机上的站点子文件夹
我有一个在远程服务器上的 IIS7 上运行的网站。我想执行以下操作:
- 在根虚拟目录下创建一个新的子文件夹。
- 创建一个新的应用程序池。
- 将此新的应用程序池添加到新的子文件夹
通常,我会在 IIS 中手动执行此操作,首先创建应用程序池,然后右键单击子文件夹并选择“添加应用程序”,但我需要在 C# 中以编程方式执行此操作。我已经设法使上述第 1 点和第 2 点起作用,但我找不到将应用程序添加到子文件夹的方法。
这是我迄今为止为 1 和 2 使用的代码:
ServerManager mgr = new ServerManager();
ApplicationPool myAppPool = mgr.ApplicationPools.Add("MyAppPool");
myAppPool.AutoStart = true;
myAppPool.Cpu.Action = ProcessorAction.KillW3wp;
myAppPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
myAppPool.ManagedRuntimeVersion = "V4.0";
myAppPool.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService;
mgr.CommitChanges();
if (!Directory.Exists(@"D:\webroot\TestSite\NytSite"))
{
Directory.CreateDirectory(@"D:\webroot\TestSite\NytSite");
}
所以,我需要将“MyAppPool”添加到“NytSite”文件夹中...
这是否是执行此操作的正确方法?
那里有什么经验吗?
谢谢
I have a web site running on IIS7 on a remote server. I would like to do the following:
- Create a new subfolder under the root virtual directory.
- Create a new app pool.
- Add this new app pool to the new subfolder
Normally, I would do this manually in IIS by first creating the app pool, and then right-clicking the sub folder an choose "add application", but I need to do this programmatically in C#. I've managed to make the above points 1 and 2 work, but I can't find the way to adding the application to the sub folder.
This is the code I have used so far for 1 and 2:
ServerManager mgr = new ServerManager();
ApplicationPool myAppPool = mgr.ApplicationPools.Add("MyAppPool");
myAppPool.AutoStart = true;
myAppPool.Cpu.Action = ProcessorAction.KillW3wp;
myAppPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
myAppPool.ManagedRuntimeVersion = "V4.0";
myAppPool.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService;
mgr.CommitChanges();
if (!Directory.Exists(@"D:\webroot\TestSite\NytSite"))
{
Directory.CreateDirectory(@"D:\webroot\TestSite\NytSite");
}
So, I need to add "MyAppPool" to the "NytSite" folder...
Is this even the correct way to do this?
Any experiences out there?
Thnx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个新的应用程序来分配应用程序池,因此您可以这样做:
You need to create a new Application to assign an application pool, so you can do this: